Skip to content

Commit

Permalink
Fix selecting subnet IDs from subnet names
Browse files Browse the repository at this point in the history
  • Loading branch information
cPu1 committed May 16, 2022
1 parent 637d454 commit 1ea37f1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions pkg/cfn/builder/nodegroup_subnets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ var _ = Describe("AssignSubnets", func() {
},
},

setSubnetMapping: func(clusterConfig *api.ClusterConfig) {
clusterConfig.VPC.Subnets = &api.ClusterSubnets{
Public: api.NewAZSubnetMapping(),
Private: api.NewAZSubnetMapping(),
}
},

expectedErr: `subnet with ID "subnet-1" is not in the attached VPC with ID "vpc-1"`,

mockEC2: func(ec2Mock *mocksv2.EC2) {
Expand Down Expand Up @@ -426,6 +433,13 @@ var _ = Describe("AssignSubnets", func() {
},
},

setSubnetMapping: func(clusterConfig *api.ClusterConfig) {
clusterConfig.VPC.Subnets = &api.ClusterSubnets{
Public: api.NewAZSubnetMapping(),
Private: api.NewAZSubnetMapping(),
}
},

mockEC2: func(ec2Mock *mocksv2.EC2) {
mockDescribeSubnets(ec2Mock, "us-west-2d", vpcID)
mockDescribeAZs(ec2Mock, []ec2types.AvailabilityZone{
Expand All @@ -446,6 +460,50 @@ var _ = Describe("AssignSubnets", func() {

expectedSubnetIDs: []string{"subnet-1"},
}),

Entry("nodegroup with subnet names", assignSubnetsEntry{
np: &api.NodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Subnets: []string{"subnet-1", "subnet-2", "subnet-3"},
},
},
mockEC2: func(ec2Mock *mocksv2.EC2) {
mockDescribeAZs(ec2Mock, []ec2types.AvailabilityZone{
{
ZoneType: aws.String("availability-zone"),
ZoneName: aws.String("us-west-2a"),
},
{
ZoneType: aws.String("availability-zone"),
ZoneName: aws.String("us-west-2d"),
},
{
ZoneType: aws.String("availability-zone"),
ZoneName: aws.String("us-west-2b"),
},
})
},
setSubnetMapping: func(clusterConfig *api.ClusterConfig) {
clusterConfig.VPC.Subnets = &api.ClusterSubnets{
Public: api.AZSubnetMapping{
"subnet-1": api.AZSubnetSpec{
ID: "subnet-1a",
AZ: "us-west-1a",
},
"subnet-2": api.AZSubnetSpec{
ID: "subnet-1b",
AZ: "us-west-1b",
},
"subnet-3": api.AZSubnetSpec{
ID: "subnet-1c",
AZ: "us-west-1c",
},
},
Private: api.NewAZSubnetMapping(),
}
},
expectedSubnetIDs: []string{"subnet-1a", "subnet-1b", "subnet-1c"},
}),
)
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/vpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func SelectNodeGroupSubnets(ctx context.Context, np api.NodePool, clusterConfig
} else {
subnetMapping = clusterConfig.VPC.LocalZoneSubnets.Public
}
} else if len(ng.AvailabilityZones) > 0 {
} else {
zones = ng.AvailabilityZones
if ng.PrivateNetworking {
subnetMapping = clusterConfig.VPC.Subnets.Private
Expand Down

0 comments on commit 1ea37f1

Please sign in to comment.