Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 0989942

Browse files
committed
Merge pull request #15 from feiskyer/destroyOVSInterface
Refactor destroyOVSInterface to avoid failing
2 parents 6b5a6f2 + 175ebed commit 0989942

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

pkg/exec/exec.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ func RunCommand(cmd string, args ...string) ([]string, error) {
4747
return nil, err
4848
}
4949

50-
output, err := command.Output()
50+
output, err := command.CombinedOutput()
5151
if err != nil {
52-
return nil, err
52+
return []string{string(output)}, err
5353
}
5454
return strings.Split(strings.TrimSpace(string(output)), "\n"), nil
5555
}

pkg/kubestack/kubestack.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ func NewKubeHandler(driver *common.OpenStack) *KubeHandler {
4343
}
4444

4545
func (h *KubeHandler) Serve(addr string) error {
46+
glog.V(1).Infof("Starting kubestack at %s", addr)
4647
l, err := net.Listen("tcp", addr)
4748
if err != nil {
48-
glog.Fatal("Failed to listen: %s", addr)
49+
glog.Fatalf("Failed to listen: %s", addr)
4950
return err
5051
}
5152
return h.server.Serve(l)

pkg/plugins/openvswitch/openvswitch.go

+26-15
Original file line numberDiff line numberDiff line change
@@ -351,34 +351,45 @@ func (p *OVSPlugin) SetupInterface(podName, podInfraContainerID string, port *po
351351
return nil
352352
}
353353

354-
func (p *OVSPlugin) destroyOVSInterface(podName, podInfraContainerID string, port *ports.Port) error {
355-
_, qvo := p.buildVethName(port.ID)
356-
_, err := exec.RunCommand("ip", "link", "delete", qvo)
354+
func (p *OVSPlugin) destroyOVSInterface(podName, podInfraContainerID, portID string) error {
355+
qvb, qvo := p.buildVethName(portID)
356+
bridge := p.buildBridgeName(portID)
357+
358+
output, err := exec.RunCommand("brctl", "delif", bridge, qvb)
357359
if err != nil {
358-
glog.V(5).Infof("Warning: DestroyInterface failed: %v", err)
360+
glog.Warningf("Warning: brctl delif %s failed: %v, %v", qvb, output, err)
359361
}
360362

361-
_, err = exec.RunCommand("ovs-vsctl", "-vconsole:off", "--if-exists", "del-port", qvo)
363+
output, err = exec.RunCommand("ip", "link", "set", "dev", bridge, "down")
362364
if err != nil {
363-
glog.V(5).Infof("Warning: DestroyInterface failed: %v", err)
365+
glog.Warningf("Warning: set bridge %s down failed: %v, %v", bridge, output, err)
364366
}
365367

366-
bridge := p.buildBridgeName(port.ID)
367-
_, err = exec.RunCommand("ip", "link", "set", bridge, "down")
368+
output, err = exec.RunCommand("brctl", "delbr", bridge)
368369
if err != nil {
369-
glog.V(5).Infof("Warning: DestroyInterface failed: %v", err)
370+
glog.Warningf("Warning: delete bridge %s failed: %v, %v", bridge, output, err)
370371
}
371372

372-
_, err = exec.RunCommand("brctl", "delbr", bridge)
373+
output, err = exec.RunCommand("ovs-vsctl", "-vconsole:off", "--if-exists", "del-port", qvo)
373374
if err != nil {
374-
glog.V(5).Infof("Warning: DestroyInterface failed: %v", err)
375+
glog.Warningf("Warning: ovs del-port %s failed: %v, %v", qvo, output, err)
376+
}
377+
378+
output, err = exec.RunCommand("ip", "link", "set", "dev", qvo, "down")
379+
if err != nil {
380+
glog.Warningf("Warning: set dev %s down failed: %v, %v", qvo, output, err)
381+
}
382+
383+
output, err = exec.RunCommand("ip", "link", "delete", "dev", qvo)
384+
if err != nil {
385+
glog.Warningf("Warning: delete dev %s failed: %v, %v", qvo, output, err)
375386
}
376387

377388
return nil
378389
}
379390

380-
func (p *OVSPlugin) destroyDockerInterface(podName, podInfraContainerID string, port *ports.Port) error {
381-
tapName, _ := p.buildTapName(port.ID)
391+
func (p *OVSPlugin) destroyDockerInterface(podName, podInfraContainerID, portID string) error {
392+
tapName, _ := p.buildTapName(portID)
382393
_, err := exec.RunCommand("ip", "link", "delete", tapName)
383394
if err != nil {
384395
glog.V(5).Infof("Warning: DestroyInterface failed: %v", err)
@@ -401,11 +412,11 @@ func (p *OVSPlugin) destroyDockerInterface(podName, podInfraContainerID string,
401412
}
402413

403414
func (p *OVSPlugin) DestroyInterface(podName, podInfraContainerID string, port *ports.Port, containerRuntime string) error {
404-
p.destroyOVSInterface(podName, podInfraContainerID, port)
415+
p.destroyOVSInterface(podName, podInfraContainerID, port.ID)
405416

406417
switch containerRuntime {
407418
case runtimeTypeDocker:
408-
p.destroyDockerInterface(podName, podInfraContainerID, port)
419+
p.destroyDockerInterface(podName, podInfraContainerID, port.ID)
409420
default:
410421
glog.V(4).Infof("DestroyInterface for %s done", containerRuntime)
411422
}

0 commit comments

Comments
 (0)