From 08d25178d4718f3aa4e09fdf81cbe0c9d4a5a947 Mon Sep 17 00:00:00 2001 From: Sunyanan Choochotkaew Date: Mon, 9 Sep 2024 11:45:13 +0900 Subject: [PATCH] fix: ignore built-in ipam on cmdDel Signed-off-by: Sunyanan Choochotkaew --- cni/plugins/main/multi-nic/multi-nic.go | 6 ++++-- cni/plugins/main/multi-nic/utils.go | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cni/plugins/main/multi-nic/multi-nic.go b/cni/plugins/main/multi-nic/multi-nic.go index a36707e4..88fe13fc 100644 --- a/cni/plugins/main/multi-nic/multi-nic.go +++ b/cni/plugins/main/multi-nic/multi-nic.go @@ -112,7 +112,9 @@ func cmdAdd(args *skel.CmdArgs) error { // Invoke ipam del if err to avoid ip leak defer func() { if err != nil { - ipam.ExecDel(n.IPAM.Type, args.StdinData) + if !isBuiltInIPAM(n.IPAM.Type) { + ipam.ExecDel(n.IPAM.Type, args.StdinData) + } } }() @@ -233,7 +235,7 @@ func cmdDel(args *skel.CmdArgs) error { } utils.Logger.Debug(fmt.Sprintf("Received an DEL request for: conf=%v", n)) // On chained invocation, IPAM block can be empty - if n.IPAM.Type != "" { + if n.IPAM.Type != "" && !isBuiltInIPAM(n.IPAM.Type) { injectedStdIn := injectMaster(args.StdinData, n.MasterNetAddrs, n.Masters, n.DeviceIDs) if n.IPAM.Type != "multi-nic-ipam" { err = ipam.ExecDel(n.IPAM.Type, injectedStdIn) diff --git a/cni/plugins/main/multi-nic/utils.go b/cni/plugins/main/multi-nic/utils.go index af451395..a5525aa3 100644 --- a/cni/plugins/main/multi-nic/utils.go +++ b/cni/plugins/main/multi-nic/utils.go @@ -227,3 +227,8 @@ func getHostIPConfig(index int, devName string) *current.IPConfig { } return ipConf } + +// isBuiltInIPAM returns true if ipam is a built-in IPAM (host-device-ipam) +func isBuiltInIPAM(ipamType string) bool { + return ipamType == HostDeviceIPAMType +}