From 3573903a8d798981014f433a60dcec085ee5e348 Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Mon, 9 May 2016 14:54:15 -0700 Subject: [PATCH] modify kubenet mutex and add timer --- pkg/kubelet/network/kubenet/kubenet_linux.go | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index 8a59479aee5..37f671281e1 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -24,6 +24,7 @@ import ( "strings" "sync" "syscall" + "time" "github.com/vishvananda/netlink" "github.com/vishvananda/netlink/nl" @@ -238,6 +239,14 @@ func (plugin *kubenetNetworkPlugin) Capabilities() utilsets.Int { } func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.ContainerID) error { + plugin.mu.Lock() + defer plugin.mu.Unlock() + + start := time.Now() + defer func() { + glog.V(4).Infof("TearDownPod took %v for %s/%s", time.Since(start), namespace, name) + }() + pod, ok := plugin.host.GetPodByName(namespace, name) if !ok { return fmt.Errorf("pod %q cannot be found", name) @@ -290,6 +299,14 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k } func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.ContainerID) error { + plugin.mu.Lock() + defer plugin.mu.Unlock() + + start := time.Now() + defer func() { + glog.V(4).Infof("TearDownPod took %v for %s/%s", time.Since(start), namespace, name) + }() + if plugin.netConfig == nil { return fmt.Errorf("Kubenet needs a PodCIDR to tear down pods") } @@ -362,8 +379,6 @@ func buildCNIRuntimeConf(podName string, podNs string, podInfraContainerID kubec } func (plugin *kubenetNetworkPlugin) addContainerToNetwork(id kubecontainer.ContainerID, rt *libcni.RuntimeConf) error { - plugin.mu.Lock() - defer plugin.mu.Unlock() glog.V(3).Infof("Calling cni plugins to add container to network with cni runtime: %+v", rt) res, err := plugin.cniConfig.AddNetwork(plugin.netConfig, rt) if err != nil { @@ -378,8 +393,6 @@ func (plugin *kubenetNetworkPlugin) addContainerToNetwork(id kubecontainer.Conta } func (plugin *kubenetNetworkPlugin) delContainerFromNetwork(id kubecontainer.ContainerID, rt *libcni.RuntimeConf) error { - plugin.mu.Lock() - defer plugin.mu.Unlock() glog.V(3).Infof("Calling cni plugins to remove container from network with cni runtime: %+v", rt) if err := plugin.cniConfig.DelNetwork(plugin.netConfig, rt); err != nil { return fmt.Errorf("Error removing container from network: %v", err)