fix cmdDel crash when use pod annotation "v1.multus-cni.io/default-network"

Crash happens in code line `conf.Delegates[0] = delegate` in function TryLoadPodDelegates,
because len(conf.Delegates) is 0.

Signed-off-by: Huanle Han <hanhuanle@caicloud.io>
This commit is contained in:
Huanle Han
2019-01-11 17:40:16 +08:00
committed by Huanle Han
parent f0bc4fb475
commit 49d55d6f45
2 changed files with 61 additions and 0 deletions

View File

@@ -413,6 +413,15 @@ func cmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient k8s.KubeClient) err
return logging.Errorf("Multus: Err in getting k8s args: %v", err)
}
if in.ClusterNetwork != "" {
err = k8s.GetDefaultNetworks(k8sArgs, in, kubeClient)
if err != nil {
return logging.Errorf("Multus: Failed to get clusterNetwork/defaultNetworks: %v", err)
}
// First delegate is always the master plugin
in.Delegates[0].MasterPlugin = true
}
numK8sDelegates, kc, err := k8s.TryLoadPodDelegates(k8sArgs, in, kubeClient)
if err != nil {
return err