Skip to content

Commit 857294c

Browse files
handle nil scenario
1 parent 22d6b48 commit 857294c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

azure-ipam/ipam.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,15 @@ func (p *IPAMPlugin) CmdAdd(args *cniSkel.CmdArgs) error {
136136
Mask: net.CIDRMask(ipNet.Bits(), 128), // nolint
137137
}
138138
}
139-
ipConfig.Gateway = (*gatewayIP)[i]
139+
140+
// Handle nil gatewayIP condition
141+
if gatewayIP != nil && len(*gatewayIP) > i {
142+
ipConfig.Gateway = (*gatewayIP)[i]
143+
} else {
144+
p.logger.Warn("No gateway IP returned from CNS, setting to nil", zap.Any("gatewayIP", gatewayIP), zap.Int("index", i))
145+
ipConfig.Gateway = nil
146+
}
147+
140148
cniResult.IPs[i] = ipConfig
141149
}
142150

0 commit comments

Comments
 (0)