Skip to content

Commit

Permalink
Filter CNI subnets when creating EKS NodeGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
mnitchev committed Apr 9, 2024
1 parent 71d41d4 commit 355b6d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/v1beta2/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ func (s Subnets) FilterPrivate() (res Subnets) {
return
}

// FilterNonCni returns the subnets that are NOT intended for usage with the CNI pod network
// (i.e. do NOT have the `sigs.k8s.io/cluster-api-provider-aws/association=secondary` tag).
func (s Subnets) FilterNonCni() (res Subnets) {
for _, x := range s {
if x.Tags[NameAWSSubnetAssociation] != SecondarySubnetTagValue {
res = append(res, x)
}
}
return
}

// FilterPublic returns a slice containing all subnets marked as public.
func (s Subnets) FilterPublic() (res Subnets) {
for _, x := range s {
Expand Down
1 change: 1 addition & 0 deletions pkg/cloud/scope/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (p *defaultSubnetPlacementStrategy) getSubnetsForAZs(azs []string, controlP
subnets = subnets.FilterPublic()
case expinfrav1.AZSubnetTypePrivate:
subnets = subnets.FilterPrivate()
subnets = subnets.FilterNonCni()
}
}
if len(subnets) == 0 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/cloud/scope/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ func TestSubnetPlacement(t *testing.T) {
AvailabilityZone: "eu-west-1c",
IsPublic: false,
},
infrav1.SubnetSpec{
ID: "subnet-az6",
AvailabilityZone: "eu-west-1c",
IsPublic: false,
Tags: infrav1.Tags{
infrav1.NameAWSSubnetAssociation: infrav1.SecondarySubnetTagValue,
},
},
},
logger: logger.NewLogger(klog.Background()),
expectedSubnetIDs: []string{"subnet-az3"},
Expand Down

0 comments on commit 355b6d8

Please sign in to comment.