mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2026-07-26 09:20:25 +00:00
fix(multus): preserve delegate bytes when cniVersion injection fails
CmdDel: do not clobber delegate Bytes when cniVersion injection fails. Assign to a temporary and only overwrite on success, so DEL keeps the original config instead of running with nil input, which would risk leaking the IP. Signed-off-by: Chen Tang <tangchen1234567@gmail.com>
This commit is contained in:
@@ -1086,10 +1086,14 @@ func CmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er
|
||||
// Inject cniVersion onto the raw bytes losslessly. Marshaling the
|
||||
// structured ConfList (types.NetConfList) here would strip
|
||||
// CNI-specific fields (e.g. calico's kubeconfig) and break DEL.
|
||||
v.Bytes, err = types.InjectCNIVersionInConfList(v.Bytes, in.CNIVersion)
|
||||
if err != nil {
|
||||
// error happen but continue to delete
|
||||
logging.Errorf("Multus: failed to inject cniVersion into delegate %q config: %v", v.Name, err)
|
||||
updatedBytes, injectErr := types.InjectCNIVersionInConfList(v.Bytes, in.CNIVersion)
|
||||
if injectErr != nil {
|
||||
// error happen but continue to delete; keep the original bytes
|
||||
// rather than clobbering them with nil, which would feed DEL
|
||||
// worse input than before and risk leaking the IP.
|
||||
logging.Errorf("Multus: failed to inject cniVersion into delegate %q config: %v", v.Name, injectErr)
|
||||
} else {
|
||||
v.Bytes = updatedBytes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user