Skip to content

Commit

Permalink
allow importing subnets with IPv6 only
Browse files Browse the repository at this point in the history
  • Loading branch information
TiberiuGC committed Dec 10, 2024
1 parent ee838d8 commit 940792f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
19 changes: 11 additions & 8 deletions pkg/apis/eksctl.io/v1alpha5/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ func validateLocalConfigAgainstRemote(localSubnetsConfig AZSubnetMapping, remote
if localSubnet.ID != "" && localSubnet.ID != remoteSubnet.ID {
return "", fmt.Errorf("subnet ID %q, found in config file, is not the same as subnet ID %q, found in remote VPC config", localSubnet.ID, remoteSubnet.ID)
}
if localSubnet.CIDR.String() != "" && localSubnet.CIDR.String() != remoteSubnet.CIDR.String() {
if localSubnet.CIDR.String() != "" && remoteSubnet.CIDR.String() != "" &&
localSubnet.CIDR.String() != remoteSubnet.CIDR.String() {
return "", fmt.Errorf("subnet CIDR %q, found in config file, is not the same as subnet CIDR %q, found in remote VPC config", localSubnet.CIDR.String(), remoteSubnet.CIDR.String())
}
return subnetAlias, nil
Expand Down Expand Up @@ -347,15 +348,17 @@ func validateLocalConfigAgainstRemote(localSubnetsConfig AZSubnetMapping, remote
}

func remoteSubnetToAZSubnetSpec(subnet *ec2types.Subnet) (AZSubnetSpec, error) {
subnetCIDR, err := ipnet.ParseCIDR(*subnet.CidrBlock)
if err != nil {
return AZSubnetSpec{}, fmt.Errorf("unexpected error parsing subnet CIDR %q: %w", *subnet.CidrBlock, err)
subnetSpec := AZSubnetSpec{
ID: *subnet.SubnetId,
AZ: *subnet.AvailabilityZone,
}

subnetSpec := AZSubnetSpec{
ID: *subnet.SubnetId,
AZ: *subnet.AvailabilityZone,
CIDR: subnetCIDR,
if subnet.CidrBlock != nil {
subnetCIDR, err := ipnet.ParseCIDR(*subnet.CidrBlock)
if err != nil {
return AZSubnetSpec{}, fmt.Errorf("unexpected error parsing subnet CIDR %q: %w", *subnet.CidrBlock, err)
}
subnetSpec.CIDR = subnetCIDR
}

if subnet.OutpostArn != nil {
Expand Down
25 changes: 22 additions & 3 deletions pkg/apis/eksctl.io/v1alpha5/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ type subnetCase struct {
var _ = Describe("VPC Configuration", func() {
DescribeTable("Subnet import",
func(e subnetCase) {
err := ImportSubnet(e.subnets, e.localSubnetsConfig, &ec2types.Subnet{
ec2Subnet := ec2types.Subnet{
AvailabilityZone: aws.String(e.az),
SubnetId: aws.String(e.subnetID),
CidrBlock: aws.String(e.cidr),
}, func(subnet *ec2types.Subnet) string {
}
if len(e.cidr) > 0 {
ec2Subnet.CidrBlock = aws.String(e.cidr)
}
err := ImportSubnet(e.subnets, e.localSubnetsConfig, &ec2Subnet, func(subnet *ec2types.Subnet) string {
return *subnet.AvailabilityZone
})
if e.err != "" {
Expand Down Expand Up @@ -77,6 +80,22 @@ var _ = Describe("VPC Configuration", func() {
},
}),
}),
Entry("Existing subnets w/o IPv4 CIDR", subnetCase{
subnets: AZSubnetMappingFromMap(map[string]AZSubnetSpec{
"us-east-1a": {},
}),
localSubnetsConfig: AZSubnetMappingFromMap(map[string]AZSubnetSpec{
"us-east-1a": {},
}),
az: "us-east-1a",
subnetID: "subnet-1",
expected: AZSubnetMappingFromMap(map[string]AZSubnetSpec{
"us-east-1a": {
AZ: "us-east-1a",
ID: "subnet-1",
},
}),
}),
Entry("Existing subnet with ID", subnetCase{
subnets: AZSubnetMappingFromMap(map[string]AZSubnetSpec{
"us-east-1a": {
Expand Down

0 comments on commit 940792f

Please sign in to comment.