Skip to content

Commit 5f07928

Browse files
committed
Fix OOB IPAM logic by explicitly checking for nil
In K8sClient.getIp it is assumed that after leaving the for loop ipamIP is not nil and the code goes on to access fields of the ipamIP variable, namely the status. The value is previously obtained via K8sClient.doCreateIpamIP which may return (nil nil) when the creating fails due to a reason other than the kubernetes object already existing which could be any number of reasons. This commit fixes that by explicitly checking the returned ipamIP for nil and erroring out when it is nil. There is a more thorough fix to be done here as K8sClient.doCreateIpamIP should not return (nil nil) in such cases.
1 parent 77f1cde commit 5f07928

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

plugins/oob/k8s.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (k K8sClient) getIp(
121121
return nil, fmt.Errorf("no matching subnet found for IP %s/%s", k.Namespace, ipaddr)
122122
}
123123

124-
if ipamIP.Status.Reserved != nil {
124+
if ipamIP != nil && ipamIP.Status.Reserved != nil {
125125
return net.ParseIP(ipamIP.Status.Reserved.String()), nil
126126
} else {
127127
return nil, fmt.Errorf("no reserved IP address found")

0 commit comments

Comments
 (0)