mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-20 17:10:09 +00:00
Change conditional flow to use cache file in CmdDel
This fix changes conditional flow to use net-attach-def if cache file is collapsed in CmdDel. Fix #948
This commit is contained in:
@@ -825,8 +825,25 @@ func CmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er
|
|||||||
|
|
||||||
// Read the cache to get delegates json for the pod
|
// Read the cache to get delegates json for the pod
|
||||||
netconfBytes, path, err := consumeScratchNetConf(args.ContainerID, in.CNIDir)
|
netconfBytes, path, err := consumeScratchNetConf(args.ContainerID, in.CNIDir)
|
||||||
removeCacheConf := false
|
useCacheConf := false
|
||||||
if err != nil {
|
if err == nil {
|
||||||
|
in.Delegates = []*types.DelegateNetConf{}
|
||||||
|
if err := json.Unmarshal(netconfBytes, &in.Delegates); err != nil {
|
||||||
|
logging.Errorf("Multus: failed to load netconf: %v", err)
|
||||||
|
} else {
|
||||||
|
useCacheConf = true
|
||||||
|
// check plugins field and enable ConfListPlugin if there is
|
||||||
|
for _, v := range in.Delegates {
|
||||||
|
if len(v.ConfList.Plugins) != 0 {
|
||||||
|
v.ConfListPlugin = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// First delegate is always the master plugin
|
||||||
|
in.Delegates[0].MasterPlugin = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !useCacheConf {
|
||||||
// Fetch delegates again if cache is not exist and pod info can be read
|
// Fetch delegates again if cache is not exist and pod info can be read
|
||||||
if os.IsNotExist(err) && pod != nil {
|
if os.IsNotExist(err) && pod != nil {
|
||||||
if in.ClusterNetwork != "" {
|
if in.ClusterNetwork != "" {
|
||||||
@@ -854,20 +871,6 @@ func CmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er
|
|||||||
logging.Errorf("Multus: failed to get the cached delegates file: %v, cannot properly delete", err)
|
logging.Errorf("Multus: failed to get the cached delegates file: %v, cannot properly delete", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
removeCacheConf = true
|
|
||||||
in.Delegates = []*types.DelegateNetConf{}
|
|
||||||
if err := json.Unmarshal(netconfBytes, &in.Delegates); err != nil {
|
|
||||||
return cmdErr(k8sArgs, "failed to load netconf: %v", err)
|
|
||||||
}
|
|
||||||
// check plugins field and enable ConfListPlugin if there is
|
|
||||||
for _, v := range in.Delegates {
|
|
||||||
if len(v.ConfList.Plugins) != 0 {
|
|
||||||
v.ConfListPlugin = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// First delegate is always the master plugin
|
|
||||||
in.Delegates[0].MasterPlugin = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set CNIVersion in delegate CNI config if there is no CNIVersion and multus conf have CNIVersion.
|
// set CNIVersion in delegate CNI config if there is no CNIVersion and multus conf have CNIVersion.
|
||||||
@@ -905,7 +908,7 @@ func CmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er
|
|||||||
// put "delete cache file" off later ensure have enough info delegate DEL message when Pod has been fully
|
// put "delete cache file" off later ensure have enough info delegate DEL message when Pod has been fully
|
||||||
// deleted from ETCD before sandbox cleanup success..
|
// deleted from ETCD before sandbox cleanup success..
|
||||||
if in.RetryDeleteOnError {
|
if in.RetryDeleteOnError {
|
||||||
if removeCacheConf {
|
if useCacheConf {
|
||||||
// Kubelet though this error as has been cleanup success and never retry, clean cache also
|
// Kubelet though this error as has been cleanup success and never retry, clean cache also
|
||||||
// Block sandbox cleanup error message can not contain "no such file or directory", CNI Runtime maybe should adaptor it !
|
// Block sandbox cleanup error message can not contain "no such file or directory", CNI Runtime maybe should adaptor it !
|
||||||
if e == nil || strings.Contains(e.Error(), "no such file or directory") {
|
if e == nil || strings.Contains(e.Error(), "no such file or directory") {
|
||||||
@@ -913,7 +916,8 @@ func CmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if removeCacheConf {
|
if useCacheConf {
|
||||||
|
// remove used cache file
|
||||||
_ = os.Remove(path) // lgtm[go/path-injection]
|
_ = os.Remove(path) // lgtm[go/path-injection]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user