Skip to content

Commit

Permalink
Add support for IPv6 Fargate nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
HusainZafar committed Mar 16, 2023
1 parent 982e654 commit 3997ec7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
21 changes: 20 additions & 1 deletion pkg/providers/v1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,26 @@ func (c *Cloud) NodeAddressesByProviderID(ctx context.Context, providerID string
if eni == nil || err != nil {
return nil, err
}
return getNodeAddressesForFargateNode(aws.StringValue(eni.PrivateDnsName), aws.StringValue(eni.PrivateIpAddress)), nil

var addresses []v1.NodeAddress

// Assign NodeInternalIP based on IP family
for _, family := range c.cfg.Global.NodeIPFamilies {
switch family {
case "ipv4":
nodeAddresses := getNodeAddressesForFargateNode(aws.StringValue(eni.PrivateDnsName), aws.StringValue(eni.PrivateIpAddress))
addresses = append(addresses, nodeAddresses...)
case "ipv6":
if eni.Ipv6Addresses == nil || len(eni.Ipv6Addresses) == 0 {
klog.Errorf("no Ipv6Addresses associated with the eni")
continue
}
internalIPv6Address := eni.Ipv6Addresses[0].Ipv6Address
nodeAddresses := getNodeAddressesForFargateNode(aws.StringValue(eni.PrivateDnsName), aws.StringValue(internalIPv6Address))
addresses = append(addresses, nodeAddresses...)
}
}
return addresses, nil
}

instance, err := describeInstance(c.ec2, instanceID)
Expand Down
10 changes: 9 additions & 1 deletion pkg/providers/v1/aws_fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,17 @@ func (ec2i *FakeEC2Impl) DescribeNetworkInterfaces(input *ec2.DescribeNetworkInt
return &ec2.DescribeNetworkInterfacesOutput{}, nil
}

if *filter.Values[0] == "return.private.dns.name" {
if strings.Contains(*filter.Values[0], "return.private.dns.name") {
networkInterface[0].PrivateDnsName = aws.String("ip-1-2-3-4.compute.amazon.com")
}

if *filter.Values[0] == "return.private.dns.name.ipv6" {
networkInterface[0].Ipv6Addresses = []*ec2.NetworkInterfaceIpv6Address{
{
Ipv6Address: aws.String("2001:db8:3333:4444:5555:6666:7777:8888"),
},
}
}
}

return &ec2.DescribeNetworkInterfacesOutput{
Expand Down
22 changes: 18 additions & 4 deletions pkg/providers/v1/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3795,26 +3795,40 @@ func TestNodeAddressesForFargate(t *testing.T) {
c, _ := newAWSCloud(CloudConfig{}, awsServices)

nodeAddresses, _ := c.NodeAddressesByProviderID(context.TODO(), "aws:///us-west-2c/1abc-2def/fargate-ip-return-private-dns-name.us-west-2.compute.internal")
verifyNodeAddressesForFargate(t, true, nodeAddresses)
verifyNodeAddressesForFargate(t, "IPV4", true, nodeAddresses)
}

func TestNodeAddressesForFargateIPV6Family(t *testing.T) {
awsServices := newMockedFakeAWSServices(TestClusterID)
c, _ := newAWSCloud(CloudConfig{}, awsServices)
c.cfg.Global.NodeIPFamilies = []string{"ipv6"}

nodeAddresses, _ := c.NodeAddressesByProviderID(context.TODO(), "aws:///us-west-2c/1abc-2def/fargate-ip-return-private-dns-name-ipv6.us-west-2.compute.internal")
verifyNodeAddressesForFargate(t, "IPV6", true, nodeAddresses)
}

func TestNodeAddressesForFargatePrivateIP(t *testing.T) {
awsServices := newMockedFakeAWSServices(TestClusterID)
c, _ := newAWSCloud(CloudConfig{}, awsServices)

nodeAddresses, _ := c.NodeAddressesByProviderID(context.TODO(), "aws:///us-west-2c/1abc-2def/fargate-192.168.164.88")
verifyNodeAddressesForFargate(t, false, nodeAddresses)
verifyNodeAddressesForFargate(t, "IPV4", false, nodeAddresses)
}

func verifyNodeAddressesForFargate(t *testing.T, verifyPublicIP bool, nodeAddresses []v1.NodeAddress) {
func verifyNodeAddressesForFargate(t *testing.T, ipFamily string, verifyPublicIP bool, nodeAddresses []v1.NodeAddress) {
if verifyPublicIP {
assert.Equal(t, 2, len(nodeAddresses))
assert.Equal(t, "ip-1-2-3-4.compute.amazon.com", nodeAddresses[1].Address)
assert.Equal(t, v1.NodeInternalDNS, nodeAddresses[1].Type)
} else {
assert.Equal(t, 1, len(nodeAddresses))
}
assert.Equal(t, "1.2.3.4", nodeAddresses[0].Address)

if ipFamily == "IPV4" {
assert.Equal(t, "1.2.3.4", nodeAddresses[0].Address)
} else {
assert.Equal(t, "2001:db8:3333:4444:5555:6666:7777:8888", nodeAddresses[0].Address)
}
assert.Equal(t, v1.NodeInternalIP, nodeAddresses[0].Type)
}

Expand Down

0 comments on commit 3997ec7

Please sign in to comment.