Skip to content

Commit

Permalink
Add support to IPv6 in Machine's status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MaysaMacedo committed Aug 7, 2023
1 parent 3c742d2 commit e0f6590
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
28 changes: 14 additions & 14 deletions pkg/cloud/services/compute/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,10 @@ func (is *InstanceStatus) NetworkStatus() (*InstanceNetworkStatus, error) {
return nil, fmt.Errorf("error unmarshalling addresses for instance %s: %w", is.ID(), err)
}

var addresses []corev1.NodeAddress
var IPv4addresses, addresses []corev1.NodeAddress
for i := range interfaceList {
address := &interfaceList[i]

// Only consider IPv4
if address.Version != 4 {
is.logger.V(6).Info("Ignoring IP address: only IPv4 is supported", "version", address.Version, "address", address.Address)
continue
}

var addressType corev1.NodeAddressType
switch address.Type {
case "floating":
Expand All @@ -170,14 +164,20 @@ func (is *InstanceStatus) NetworkStatus() (*InstanceNetworkStatus, error) {
is.logger.V(6).Info("Ignoring address with unknown type", "address", address.Address, "type", address.Type)
continue
}

addresses = append(addresses, corev1.NodeAddress{
Type: addressType,
Address: address.Address,
})
if address.Version == 4 {
IPv4addresses = append(IPv4addresses, corev1.NodeAddress{
Type: addressType,
Address: address.Address,
})
} else {
addresses = append(addresses, corev1.NodeAddress{
Type: addressType,
Address: address.Address,
})
}
}

addressesByNetwork[networkName] = addresses
// 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
addressesByNetwork[networkName] = append(IPv4addresses, addresses...)
}

return &InstanceNetworkStatus{addressesByNetwork}, nil
Expand Down
36 changes: 19 additions & 17 deletions pkg/cloud/services/compute/instance_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,15 @@ func TestNetworkStatus_Addresses(t *testing.T) {
},
},
{
name: "Ignore IPv6",
name: "Multiple Fixed IP and Floating IP",
addresses: map[string][]networkAddress{
"primary": {
{
Version: 4,
Addr: "192.168.0.1",
Type: "fixed",
MacAddr: macAddr3,
},
{
Version: 6,
Addr: "fe80::f816:3eff:fe56:3174",
Expand All @@ -120,11 +126,6 @@ func TestNetworkStatus_Addresses(t *testing.T) {
Addr: "fe80::f816:3eff:fe56:3175",
Type: "floating",
MacAddr: macAddr2,
}, {
Version: 4,
Addr: "192.168.0.1",
Type: "fixed",
MacAddr: macAddr3,
},
},
},
Expand Down Expand Up @@ -248,20 +249,10 @@ func TestInstanceNetworkStatus(t *testing.T) {
wantFloatingIP: "10.0.0.1",
},
{
name: "Ignore IPv6",
name: "Multiple Fixed IP and Floating IP",
addresses: map[string][]networkAddress{
"primary": {
{
Version: 6,
Addr: "fe80::f816:3eff:fe56:3174",
Type: "fixed",
MacAddr: macAddr1,
}, {
Version: 6,
Addr: "fe80::f816:3eff:fe56:3175",
Type: "floating",
MacAddr: macAddr2,
}, {
Version: 4,
Addr: "10.0.0.1",
Type: "floating",
Expand All @@ -272,6 +263,17 @@ func TestInstanceNetworkStatus(t *testing.T) {
Type: "fixed",
MacAddr: macAddr4,
},
{
Version: 6,
Addr: "fe80::f816:3eff:fe56:3174",
Type: "fixed",
MacAddr: macAddr1,
}, {
Version: 6,
Addr: "fe80::f816:3eff:fe56:3175",
Type: "floating",
MacAddr: macAddr2,
},
},
},
networkName: "primary",
Expand Down

0 comments on commit e0f6590

Please sign in to comment.