From 6cfe116375582202f75e307b3c01a314b0c6e368 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 27 Sep 2018 11:14:50 -0500 Subject: [PATCH] network/cni: more informative log messages Log details about the pod name, namespace, sandbox ID, and result. Remove some useless messages that are now redundant. --- pkg/kubelet/dockershim/network/cni/cni.go | 26 +++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/kubelet/dockershim/network/cni/cni.go b/pkg/kubelet/dockershim/network/cni/cni.go index e0bbf97c1e8..c8fbdbb315f 100644 --- a/pkg/kubelet/dockershim/network/cni/cni.go +++ b/pkg/kubelet/dockershim/network/cni/cni.go @@ -268,17 +268,11 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec // Windows doesn't have loNetwork. It comes only with Linux if plugin.loNetwork != nil { if _, err = plugin.addToNetwork(plugin.loNetwork, name, namespace, id, netnsPath, annotations); err != nil { - glog.Errorf("Error while adding to cni lo network: %s", err) return err } } _, err = plugin.addToNetwork(plugin.getDefaultNetwork(), name, namespace, id, netnsPath, annotations) - if err != nil { - glog.Errorf("Error while adding to cni network: %s", err) - return err - } - return err } @@ -296,6 +290,10 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku return plugin.deleteFromNetwork(plugin.getDefaultNetwork(), name, namespace, id, netnsPath, nil) } +func podDesc(namespace, name string, id kubecontainer.ContainerID) string { + return fmt.Sprintf("%s_%s/%s", namespace, name, id.ID) +} + func (plugin *cniNetworkPlugin) addToNetwork(network *cniNetwork, podName string, podNamespace string, podSandboxID kubecontainer.ContainerID, podNetnsPath string, annotations map[string]string) (cnitypes.Result, error) { rt, err := plugin.buildCNIRuntimeConf(podName, podNamespace, podSandboxID, podNetnsPath, annotations) if err != nil { @@ -303,14 +301,15 @@ func (plugin *cniNetworkPlugin) addToNetwork(network *cniNetwork, podName string return nil, err } + pdesc := podDesc(podNamespace, podName, podSandboxID) netConf, cniNet := network.NetworkConfig, network.CNIConfig - glog.V(4).Infof("About to add CNI network %v (type=%v)", netConf.Name, netConf.Plugins[0].Network.Type) + glog.V(4).Infof("Adding %s to network %s/%s netns %q", pdesc, netConf.Plugins[0].Network.Type, netConf.Name, podNetnsPath) res, err := cniNet.AddNetworkList(netConf, rt) if err != nil { - glog.Errorf("Error adding network: %v", err) + glog.Errorf("Error adding %s to network %s/%s: %v", pdesc, netConf.Plugins[0].Network.Type, netConf.Name, err) return nil, err } - + glog.V(4).Infof("Added %s to network %s: %v", pdesc, netConf.Name, res) return res, nil } @@ -321,22 +320,21 @@ func (plugin *cniNetworkPlugin) deleteFromNetwork(network *cniNetwork, podName s return err } + pdesc := podDesc(podNamespace, podName, podSandboxID) netConf, cniNet := network.NetworkConfig, network.CNIConfig - glog.V(4).Infof("About to del CNI network %v (type=%v)", netConf.Name, netConf.Plugins[0].Network.Type) + glog.V(4).Infof("Deleting %s from network %s/%s netns %q", pdesc, netConf.Plugins[0].Network.Type, netConf.Name, podNetnsPath) err = cniNet.DelNetworkList(netConf, rt) // The pod may not get deleted successfully at the first time. // Ignore "no such file or directory" error in case the network has already been deleted in previous attempts. if err != nil && !strings.Contains(err.Error(), "no such file or directory") { - glog.Errorf("Error deleting network: %v", err) + glog.Errorf("Error deleting %s from network %s/%s: %v", pdesc, netConf.Plugins[0].Network.Type, netConf.Name, err) return err } + glog.V(4).Infof("Deleted %s from network %s/%s", pdesc, netConf.Plugins[0].Network.Type, netConf.Name) return nil } func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string, podSandboxID kubecontainer.ContainerID, podNetnsPath string, annotations map[string]string) (*libcni.RuntimeConf, error) { - glog.V(4).Infof("Got netns path %v", podNetnsPath) - glog.V(4).Infof("Using podns path %v", podNs) - rt := &libcni.RuntimeConf{ ContainerID: podSandboxID.ID, NetNS: podNetnsPath,