Skip to content

Commit

Permalink
fix(node): do nil checking on FindBestIP util funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Jan 23, 2023
1 parent 8183b18 commit 3129bf2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/utils/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,35 @@ func GetAllNodeIPs(node *apiv1.Node) (map[apiv1.NodeAddressType][]net.IP, map[ap
}

func FindBestIPv6NodeAddress(priIP net.IP, intExtIPv6Addresses map[apiv1.NodeAddressType][]net.IP) net.IP {
if priIP.To4() == nil && priIP.To16() != nil {
if priIP != nil && priIP.To4() == nil && priIP.To16() != nil {
// the NRC's primary IP is already an IPv6 address, so we'll use that
return priIP
}
// the NRC's primary IP is not an IPv6, let's try to find the best available IPv6 address out of our
// available node addresses to use as the nextHop for our route
if len(intExtIPv6Addresses[apiv1.NodeInternalIP]) > 0 {
return intExtIPv6Addresses[apiv1.NodeInternalIP][0]
} else if len(intExtIPv6Addresses[apiv1.NodeExternalIP]) > 0 {
return intExtIPv6Addresses[apiv1.NodeExternalIP][0]
if intExtIPv6Addresses != nil {
if len(intExtIPv6Addresses[apiv1.NodeInternalIP]) > 0 {
return intExtIPv6Addresses[apiv1.NodeInternalIP][0]
} else if len(intExtIPv6Addresses[apiv1.NodeExternalIP]) > 0 {
return intExtIPv6Addresses[apiv1.NodeExternalIP][0]
}
}
return nil
}

func FindBestIPv4NodeAddress(priIP net.IP, intExtIPv4Addresses map[apiv1.NodeAddressType][]net.IP) net.IP {
if priIP.To4() != nil {
if priIP != nil && priIP.To4() != nil {
// the NRC's primary IP is already an IPv6 address, so we'll use that
return priIP
}
// the NRC's primary IP is not an IPv6, let's try to find the best available IPv6 address out of our
// available node addresses to use as the nextHop for our route
if len(intExtIPv4Addresses[apiv1.NodeInternalIP]) > 0 {
return intExtIPv4Addresses[apiv1.NodeInternalIP][0]
} else if len(intExtIPv4Addresses[apiv1.NodeExternalIP]) > 0 {
return intExtIPv4Addresses[apiv1.NodeExternalIP][0]
if intExtIPv4Addresses != nil {
if len(intExtIPv4Addresses[apiv1.NodeInternalIP]) > 0 {
return intExtIPv4Addresses[apiv1.NodeInternalIP][0]
} else if len(intExtIPv4Addresses[apiv1.NodeExternalIP]) > 0 {
return intExtIPv4Addresses[apiv1.NodeExternalIP][0]
}
}
return nil
}
Expand Down

0 comments on commit 3129bf2

Please sign in to comment.