From 1b58bed5a6867cd7090b6ec4836815f4459d84ee Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Thu, 19 Nov 2020 10:30:12 +0100 Subject: [PATCH] clarify cmdAdd error it can happen that a CNI Add operation is canceled because the runtime sends a CNI Del too fast, so the pod was already deleted when multus try to set the network status annotations. Since multus is an executable and can not persist state, it can't track the CNI requests that are done in parallel, but it can assume that, if it was able to get the pod from the API, and in a subsequent request the pod no longer exists, it is because it was deleted. Signed-off-by: Antonio Ojea --- multus/multus.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/multus/multus.go b/multus/multus.go index 9640dfda8..1726a4fe8 100644 --- a/multus/multus.go +++ b/multus/multus.go @@ -49,12 +49,16 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) -var version = "master@git" -var commit = "unknown commit" -var date = "unknown date" +var ( + version = "master@git" + commit = "unknown commit" + date = "unknown date" +) -var pollDuration = 1000 * time.Millisecond -var pollTimeout = 45 * time.Second +var ( + pollDuration = 1000 * time.Millisecond + pollTimeout = 45 * time.Second +) func printVersionString() string { return fmt.Sprintf("multus-cni version:%s, commit:%s, date:%s", @@ -608,7 +612,7 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c result = tmpResult } - //create the network status, only in case Multus as kubeconfig + // create the network status, only in case Multus as kubeconfig if n.Kubeconfig != "" && kc != nil { if !types.CheckSystemNamespaces(string(k8sArgs.K8S_POD_NAME), n.SystemNamespaces) { delegateNetStatus, err := nadutils.CreateNetworkStatus(tmpResult, delegate.Name, delegate.MasterPlugin) @@ -621,11 +625,14 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c } } - //set the network status annotation in apiserver, only in case Multus as kubeconfig + // set the network status annotation in apiserver, only in case Multus as kubeconfig if n.Kubeconfig != "" && kc != nil { if !types.CheckSystemNamespaces(string(k8sArgs.K8S_POD_NAME), n.SystemNamespaces) { err = k8s.SetNetworkStatus(kubeClient, k8sArgs, netStatus, n) if err != nil { + if strings.Contains(err.Error(), "failed to query the pod") { + return nil, cmdErr(k8sArgs, "error setting the networks status, pod was already deleted: %v", err) + } return nil, cmdErr(k8sArgs, "error setting the networks status: %v", err) } } @@ -803,7 +810,6 @@ func cmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er } func main() { - // Init command line flags to clear vendored packages' one, especially in init() flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)