Skip to content

Commit f1c31ef

Browse files
authored
[occm] fix node internal/external IP order (#2719)
1 parent b7edee4 commit f1c31ef

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

pkg/openstack/loadbalancer.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,22 +387,22 @@ func nodeAddressForLB(node *corev1.Node, preferredIPFamily corev1.IPFamily) (str
387387
}
388388

389389
allowedAddrTypes := []corev1.NodeAddressType{corev1.NodeInternalIP, corev1.NodeExternalIP}
390-
for _, addr := range addrs {
391-
if !slices.Contains(allowedAddrTypes, addr.Type) {
392-
// Skip the address type that is not allowed
393-
continue
394-
}
395-
switch preferredIPFamily {
396-
case corev1.IPv4Protocol:
397-
if netutils.IsIPv4String(addr.Address) {
398-
return addr.Address, nil
399-
}
400-
case corev1.IPv6Protocol:
401-
if netutils.IsIPv6String(addr.Address) {
402-
return addr.Address, nil
390+
for _, allowedAddrType := range allowedAddrTypes {
391+
for _, addr := range addrs {
392+
if addr.Type == allowedAddrType {
393+
switch preferredIPFamily {
394+
case corev1.IPv4Protocol:
395+
if netutils.IsIPv4String(addr.Address) {
396+
return addr.Address, nil
397+
}
398+
case corev1.IPv6Protocol:
399+
if netutils.IsIPv6String(addr.Address) {
400+
return addr.Address, nil
401+
}
402+
default:
403+
return addr.Address, nil
404+
}
403405
}
404-
default:
405-
return addr.Address, nil
406406
}
407407
}
408408

pkg/openstack/loadbalancer_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,14 +1523,14 @@ func Test_nodeAddressForLB(t *testing.T) {
15231523
node: &corev1.Node{
15241524
Status: corev1.NodeStatus{
15251525
Addresses: []corev1.NodeAddress{
1526-
{
1527-
Type: corev1.NodeInternalIP,
1528-
Address: "192.168.1.1",
1529-
},
15301526
{
15311527
Type: corev1.NodeExternalIP,
15321528
Address: "192.168.1.2",
15331529
},
1530+
{
1531+
Type: corev1.NodeInternalIP,
1532+
Address: "192.168.1.1",
1533+
},
15341534
},
15351535
},
15361536
},
@@ -1545,14 +1545,14 @@ func Test_nodeAddressForLB(t *testing.T) {
15451545
node: &corev1.Node{
15461546
Status: corev1.NodeStatus{
15471547
Addresses: []corev1.NodeAddress{
1548-
{
1549-
Type: corev1.NodeInternalIP,
1550-
Address: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
1551-
},
15521548
{
15531549
Type: corev1.NodeExternalIP,
15541550
Address: "2001:0db8:85a3:3333:1111:8a2e:9999:8888",
15551551
},
1552+
{
1553+
Type: corev1.NodeInternalIP,
1554+
Address: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
1555+
},
15561556
},
15571557
},
15581558
},

0 commit comments

Comments
 (0)