Skip to content

Commit

Permalink
Include IPv6 addresses in Machine status
Browse files Browse the repository at this point in the history
This includes any IPv6 addresses associated with an instance's network
interfaces in the Machine object's status.  They are listed with type
NodeInternalIP to match what KNI is doing:

  openshift-kni/origin@7db21c1
  • Loading branch information
bison committed Dec 12, 2019
1 parent 07a8fd7 commit 816e127
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,20 @@ func extractNodeAddresses(instance *ec2.Instance) ([]corev1.NodeAddress, error)
continue
}

// Treating IPv6 addresses as type NodeInternalIP to match what the KNI
// patch to the AWS cloud-provider code is doing:
//
// https://github.com/openshift-kni/origin/commit/7db21c1e26a344e25ae1b825d4f21e7bef5c3650
for _, ipv6Address := range networkInterface.Ipv6Addresses {
if addr := aws.StringValue(ipv6Address.Ipv6Address); addr != "" {
ip := net.ParseIP(addr)
if ip == nil {
return nil, fmt.Errorf("EC2 instance had invalid IPv6 address: %s (%q)", aws.StringValue(instance.InstanceId), addr)
}
addresses = append(addresses, corev1.NodeAddress{Type: corev1.NodeInternalIP, Address: ip.String()})
}
}

for _, internalIP := range networkInterface.PrivateIpAddresses {
if ipAddress := aws.StringValue(internalIP.PrivateIpAddress); ipAddress != "" {
ip := net.ParseIP(ipAddress)
Expand Down
28 changes: 28 additions & 0 deletions pkg/actuators/machine/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,34 @@ func TestExtractNodeAddresses(t *testing.T) {
{Type: corev1.NodeHostName, Address: "ec2.example.net"},
},
},
{
testcase: "ipv6-private",
instance: &ec2.Instance{
PrivateDnsName: aws.String("ec2.example.net"),
NetworkInterfaces: []*ec2.InstanceNetworkInterface{
{
Status: aws.String(ec2.NetworkInterfaceStatusInUse),
Ipv6Addresses: []*ec2.InstanceIpv6Address{
{
Ipv6Address: aws.String("2600:1f18:4254:5100:ef8a:7b65:7782:9248"),
},
},
PrivateIpAddresses: []*ec2.InstancePrivateIpAddress{
{
Primary: aws.Bool(true),
PrivateIpAddress: aws.String("10.0.0.5"),
},
},
},
},
},
expectedAddresses: []corev1.NodeAddress{
{Type: corev1.NodeInternalIP, Address: "2600:1f18:4254:5100:ef8a:7b65:7782:9248"},
{Type: corev1.NodeInternalIP, Address: "10.0.0.5"},
{Type: corev1.NodeInternalDNS, Address: "ec2.example.net"},
{Type: corev1.NodeHostName, Address: "ec2.example.net"},
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 816e127

Please sign in to comment.