diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index a0a0b55ea18..cdc83c54cca 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -370,7 +370,8 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i } // no cached CIDR is Ok during teardown - if cidr, ok := plugin.podCIDRs[id]; ok { + cidr, hasCIDR := plugin.podCIDRs[id] + if hasCIDR { glog.V(5).Infof("Removing pod CIDR %s from shaper", cidr) // shaper wants /32 if addr, _, err := net.ParseCIDR(cidr); err != nil { @@ -380,6 +381,11 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i } } if err := plugin.delContainerFromNetwork(plugin.netConfig, network.DefaultInterfaceName, namespace, name, id); err != nil { + // This is to prevent returning error when TearDownPod is called twice on the same pod. This helps to reduce event pollution. + if !hasCIDR { + glog.Warningf("Failed to delete container from kubenet: %v", err) + return nil + } return err } delete(plugin.podCIDRs, id)