Skip to content

Commit b71decb

Browse files
committed
sdn: try cleaning up OVS rules even if sandbox is gone
If a sandbox is deleted underneath kubernetes its netns will be gone and its veth interface will be deleted by the kernel. That means we can't inspect the veth for its IP address and other details, which are used to remove OVS flows for the interface. But we've already got code to find out the IP using the sandbox ID which kubelet passes down to us. Let's use that code to at least delete the stale OVS flows. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1518684
1 parent 9fc116a commit b71decb

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pkg/network/node/ovscontroller.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,17 @@ func (oc *ovsController) TearDownPod(hostVeth, podIP, sandboxID string) error {
402402
podIP = ip
403403
}
404404

405-
if err := oc.cleanupPodFlows(podIP); err != nil {
405+
err := oc.cleanupPodFlows(podIP)
406+
if err != nil {
406407
return err
407408
}
408-
_ = oc.SetPodBandwidth(hostVeth, -1, -1)
409-
return oc.ovs.DeletePort(hostVeth)
409+
410+
// veth may have already been destroyed if the container was deleted out-of-band
411+
if hostVeth != "" {
412+
_ = oc.SetPodBandwidth(hostVeth, -1, -1)
413+
err = oc.ovs.DeletePort(hostVeth)
414+
}
415+
return err
410416
}
411417

412418
func policyNames(policies []networkapi.EgressNetworkPolicy) string {

pkg/network/node/pod.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,23 +679,26 @@ func (m *podManager) teardown(req *cniserver.PodRequest) error {
679679
defer PodOperationsLatency.WithLabelValues(PodOperationTeardown).Observe(sinceInMicroseconds(time.Now()))
680680

681681
netnsValid := true
682-
if err := ns.IsNSorErr(req.Netns); err != nil {
682+
err := ns.IsNSorErr(req.Netns)
683+
if err != nil {
683684
if _, ok := err.(ns.NSPathNotExistErr); ok {
684685
glog.V(3).Infof("teardown called on already-destroyed pod %s/%s; only cleaning up IPAM", req.PodNamespace, req.PodName)
685686
netnsValid = false
686687
}
687688
}
688689

689-
errList := []error{}
690+
var hostVethName string
691+
var podIP string
690692
if netnsValid {
691-
hostVethName, _, podIP, err := getVethInfo(req.Netns, podInterfaceName)
693+
hostVethName, _, podIP, err = getVethInfo(req.Netns, podInterfaceName)
692694
if err != nil {
693695
return err
694696
}
697+
}
695698

696-
if err := m.ovs.TearDownPod(hostVethName, podIP, req.SandboxID); err != nil {
697-
errList = append(errList, err)
698-
}
699+
errList := []error{}
700+
if err := m.ovs.TearDownPod(hostVethName, podIP, req.SandboxID); err != nil {
701+
errList = append(errList, err)
699702
}
700703

701704
if err := m.ipamDel(req.SandboxID); err != nil {

0 commit comments

Comments
 (0)