Skip to content

Commit 5926f47

Browse files
committed
Add support to IPv6 in Machine's status
Dual-stack clusters require that the Machine's status contains the IPv6 address. This commit removed the check that would skip the addition of IPv6 to the Machines. Also, it ensures the IPv4 addresses of each Network remains being the first ones listed in the Machines given there are operations that rely on the first address of each network.
1 parent 3c742d2 commit 5926f47

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

pkg/cloud/services/compute/instance_types.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,10 @@ func (is *InstanceStatus) NetworkStatus() (*InstanceNetworkStatus, error) {
150150
return nil, fmt.Errorf("error unmarshalling addresses for instance %s: %w", is.ID(), err)
151151
}
152152

153-
var addresses []corev1.NodeAddress
153+
var IPv4addresses, IPv6addresses []corev1.NodeAddress
154154
for i := range interfaceList {
155155
address := &interfaceList[i]
156156

157-
// Only consider IPv4
158-
if address.Version != 4 {
159-
is.logger.V(6).Info("Ignoring IP address: only IPv4 is supported", "version", address.Version, "address", address.Address)
160-
continue
161-
}
162-
163157
var addressType corev1.NodeAddressType
164158
switch address.Type {
165159
case "floating":
@@ -170,14 +164,20 @@ func (is *InstanceStatus) NetworkStatus() (*InstanceNetworkStatus, error) {
170164
is.logger.V(6).Info("Ignoring address with unknown type", "address", address.Address, "type", address.Type)
171165
continue
172166
}
173-
174-
addresses = append(addresses, corev1.NodeAddress{
175-
Type: addressType,
176-
Address: address.Address,
177-
})
167+
if address.Version == 4 {
168+
IPv4addresses = append(IPv4addresses, corev1.NodeAddress{
169+
Type: addressType,
170+
Address: address.Address,
171+
})
172+
} else {
173+
IPv6addresses = append(IPv6addresses, corev1.NodeAddress{
174+
Type: addressType,
175+
Address: address.Address,
176+
})
177+
}
178178
}
179-
180-
addressesByNetwork[networkName] = addresses
179+
// Maintain IPv4 addresses being first ones on Machine's status given there are operations, e.g. reconcile load-balancer member, that use the first address by network type
180+
addressesByNetwork[networkName] = append(IPv4addresses, IPv6addresses...)
181181
}
182182

183183
return &InstanceNetworkStatus{addressesByNetwork}, nil

pkg/cloud/services/compute/instance_types_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestNetworkStatus_Addresses(t *testing.T) {
107107
},
108108
},
109109
{
110-
name: "Ignore IPv6",
110+
name: "Multiple Fixed IP and Floating IP",
111111
addresses: map[string][]networkAddress{
112112
"primary": {
113113
{
@@ -133,6 +133,14 @@ func TestNetworkStatus_Addresses(t *testing.T) {
133133
Type: corev1.NodeInternalIP,
134134
Address: "192.168.0.1",
135135
},
136+
{
137+
Type: corev1.NodeInternalIP,
138+
Address: "fe80::f816:3eff:fe56:3174",
139+
},
140+
{
141+
Type: corev1.NodeExternalIP,
142+
Address: "fe80::f816:3eff:fe56:3175",
143+
},
136144
},
137145
},
138146
{
@@ -248,7 +256,7 @@ func TestInstanceNetworkStatus(t *testing.T) {
248256
wantFloatingIP: "10.0.0.1",
249257
},
250258
{
251-
name: "Ignore IPv6",
259+
name: "Multiple Fixed IP and Floating IP",
252260
addresses: map[string][]networkAddress{
253261
"primary": {
254262
{

0 commit comments

Comments
 (0)