Skip to content

Commit

Permalink
[occm] fix node internal/external IP order (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus authored Nov 18, 2024
1 parent b7edee4 commit f1c31ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
30 changes: 15 additions & 15 deletions pkg/openstack/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,22 @@ func nodeAddressForLB(node *corev1.Node, preferredIPFamily corev1.IPFamily) (str
}

allowedAddrTypes := []corev1.NodeAddressType{corev1.NodeInternalIP, corev1.NodeExternalIP}
for _, addr := range addrs {
if !slices.Contains(allowedAddrTypes, addr.Type) {
// Skip the address type that is not allowed
continue
}
switch preferredIPFamily {
case corev1.IPv4Protocol:
if netutils.IsIPv4String(addr.Address) {
return addr.Address, nil
}
case corev1.IPv6Protocol:
if netutils.IsIPv6String(addr.Address) {
return addr.Address, nil
for _, allowedAddrType := range allowedAddrTypes {
for _, addr := range addrs {
if addr.Type == allowedAddrType {
switch preferredIPFamily {
case corev1.IPv4Protocol:
if netutils.IsIPv4String(addr.Address) {
return addr.Address, nil
}
case corev1.IPv6Protocol:
if netutils.IsIPv6String(addr.Address) {
return addr.Address, nil
}
default:
return addr.Address, nil
}
}
default:
return addr.Address, nil
}
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/openstack/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,14 +1523,14 @@ func Test_nodeAddressForLB(t *testing.T) {
node: &corev1.Node{
Status: corev1.NodeStatus{
Addresses: []corev1.NodeAddress{
{
Type: corev1.NodeInternalIP,
Address: "192.168.1.1",
},
{
Type: corev1.NodeExternalIP,
Address: "192.168.1.2",
},
{
Type: corev1.NodeInternalIP,
Address: "192.168.1.1",
},
},
},
},
Expand All @@ -1545,14 +1545,14 @@ func Test_nodeAddressForLB(t *testing.T) {
node: &corev1.Node{
Status: corev1.NodeStatus{
Addresses: []corev1.NodeAddress{
{
Type: corev1.NodeInternalIP,
Address: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
},
{
Type: corev1.NodeExternalIP,
Address: "2001:0db8:85a3:3333:1111:8a2e:9999:8888",
},
{
Type: corev1.NodeInternalIP,
Address: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
},
},
},
},
Expand Down

0 comments on commit f1c31ef

Please sign in to comment.