Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Filter CNI subnets when creating EKS NodeGroup #4800

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading