mirror of https://github.com/k3s-io/k3s
Merge pull request #69159 from dcbw/cni-log-messages
network/cni: more informative log messagespull/58/head
commit
823fca1d93
|
@ -268,17 +268,11 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
|
||||||
// Windows doesn't have loNetwork. It comes only with Linux
|
// Windows doesn't have loNetwork. It comes only with Linux
|
||||||
if plugin.loNetwork != nil {
|
if plugin.loNetwork != nil {
|
||||||
if _, err = plugin.addToNetwork(plugin.loNetwork, name, namespace, id, netnsPath, annotations); err != 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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = plugin.addToNetwork(plugin.getDefaultNetwork(), name, namespace, id, netnsPath, annotations)
|
_, 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
|
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)
|
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) {
|
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)
|
rt, err := plugin.buildCNIRuntimeConf(podName, podNamespace, podSandboxID, podNetnsPath, annotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -303,14 +301,15 @@ func (plugin *cniNetworkPlugin) addToNetwork(network *cniNetwork, podName string
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pdesc := podDesc(podNamespace, podName, podSandboxID)
|
||||||
netConf, cniNet := network.NetworkConfig, network.CNIConfig
|
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)
|
res, err := cniNet.AddNetworkList(netConf, rt)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
glog.V(4).Infof("Added %s to network %s: %v", pdesc, netConf.Name, res)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,22 +320,21 @@ func (plugin *cniNetworkPlugin) deleteFromNetwork(network *cniNetwork, podName s
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pdesc := podDesc(podNamespace, podName, podSandboxID)
|
||||||
netConf, cniNet := network.NetworkConfig, network.CNIConfig
|
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)
|
err = cniNet.DelNetworkList(netConf, rt)
|
||||||
// The pod may not get deleted successfully at the first time.
|
// 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.
|
// 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") {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
glog.V(4).Infof("Deleted %s from network %s/%s", pdesc, netConf.Plugins[0].Network.Type, netConf.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string, podSandboxID kubecontainer.ContainerID, podNetnsPath string, annotations map[string]string) (*libcni.RuntimeConf, error) {
|
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{
|
rt := &libcni.RuntimeConf{
|
||||||
ContainerID: podSandboxID.ID,
|
ContainerID: podSandboxID.ID,
|
||||||
NetNS: podNetnsPath,
|
NetNS: podNetnsPath,
|
||||||
|
|
Loading…
Reference in New Issue