Skip to content

Commit

Permalink
fix: ignore built-in ipam on cmdDel
Browse files Browse the repository at this point in the history
Signed-off-by: Sunyanan Choochotkaew <[email protected]>
  • Loading branch information
sunya-ch committed Sep 9, 2024
1 parent 770266d commit 08d2517
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cni/plugins/main/multi-nic/multi-nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}()

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cni/plugins/main/multi-nic/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 08d2517

Please sign in to comment.