Skip to content

Commit

Permalink
support nat64 and dns64 (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
DockToFuture authored Oct 14, 2024
1 parent 8975d72 commit a136b35
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/aws/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,7 @@ func (c *Client) describeRouteTables(ctx context.Context, input *ec2.DescribeRou
NatGatewayId: route.NatGatewayId,
EgressOnlyInternetGatewayId: route.EgressOnlyInternetGatewayId,
DestinationPrefixListId: route.DestinationPrefixListId,
DestinationIpv6CidrBlock: route.DestinationIpv6CidrBlock,
})
}
for _, assoc := range item.Associations {
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/infrastructure/infraflow/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
defaultLongTimeout = 3 * time.Minute
allIPv4 = "0.0.0.0/0"
allIPv6 = "::/0"
nat64Prefix = "64:ff9b::/96"
)

// Reconcile creates and runs the flow to reconcile the AWS infrastructure.
Expand Down Expand Up @@ -674,6 +675,7 @@ func (c *FlowContext) ensureZones(ctx context.Context) error {
CidrBlock: zone.Workers,
Ipv6Native: ptr.To(!isIPv4(c.ipFamilies)),
EnableResourceNameDnsAAAARecordOnLaunch: ptr.To(!isIPv4(c.ipFamilies)),
EnableDns64: ptr.To(!isIPv4(c.ipFamilies)),
},
&awsclient.Subnet{
Tags: tagsPrivate,
Expand Down Expand Up @@ -1108,6 +1110,10 @@ func (c *FlowContext) ensurePrivateRoutingTable(zoneName string) flow.TaskFn {
DestinationIpv6CidrBlock: ptr.To(allIPv6),
EgressOnlyInternetGatewayId: c.state.Get(IdentifierEgressOnlyInternetGateway),
})
routes = append(routes, &awsclient.Route{
DestinationIpv6CidrBlock: ptr.To(nat64Prefix),
NatGatewayId: child.Get(IdentifierZoneNATGateway),
})
}

desired := &awsclient.RouteTable{
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/infrastructure/templates/main.tpl.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ resource "aws_subnet" "nodes_z{{ $index }}" {
availability_zone = "{{ $zone.name }}"

{{ if $.isIPv6 }}
enable_dns64 = true
ipv6_native = true
assign_ipv6_address_on_creation = true
ipv6_cidr_block = "${cidrsubnet({{ $.vpc.ipv6CidrBlock }}, 8, (({{ $index }} * 3)))}"
Expand Down Expand Up @@ -344,6 +345,16 @@ resource "aws_route" "private_utility_z{{ $index }}_nat" {
}

{{- if $.isIPv6 }}
resource "aws_route" "private_utility_z{{ $index }}_nat_64" {
route_table_id = aws_route_table.routetable_private_utility_z{{ $index }}.id
destination_ipv6_cidr_block = "64:ff9b::/96"
nat_gateway_id = aws_nat_gateway.natgw_z{{ $index }}.id

timeouts {
create = "5m"
}
}

resource "aws_route" "private_utility_z{{ $index }}_egw" {
route_table_id = aws_route_table.routetable_private_utility_z{{ $index }}.id
destination_ipv6_cidr_block = "::/0"
Expand Down
8 changes: 8 additions & 0 deletions test/integration/infrastructure/infrastructure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ func verifyCreation(
sshPublicKeyDigest = "46:ca:46:0e:8e:1d:bc:0c:45:31:ee:0f:43:5f:9b:f1"
allCIDR = "0.0.0.0/0"
allCIDRIPV6 = "::/0"
nat64Prefix = "64:ff9b::/96"
)

var (
Expand Down Expand Up @@ -1357,6 +1358,13 @@ func verifyCreation(
}
}

expectedRoutes = append(expectedRoutes, &ec2.Route{
DestinationIpv6CidrBlock: awssdk.String(nat64Prefix),
NatGatewayId: describeNatGatewaysOutput.NatGateways[0].NatGatewayId,
Origin: awssdk.String("CreateRoute"),
State: awssdk.String("active"),
})

expectedRoutes = append(expectedRoutes, &ec2.Route{
DestinationIpv6CidrBlock: awssdk.String(allCIDRIPV6),
EgressOnlyInternetGatewayId: eoigs[0].EgressOnlyInternetGatewayId,
Expand Down

0 comments on commit a136b35

Please sign in to comment.