Skip to content

Commit

Permalink
Merge pull request #4800 from giantswarm/pr-eks-cni-subnet
Browse files Browse the repository at this point in the history
✨ Filter CNI subnets when creating EKS NodeGroup
  • Loading branch information
k8s-ci-robot authored May 20, 2024
2 parents 4f24769 + 355b6d8 commit 2d2371f
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 @@ -715,6 +715,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 2d2371f

Please sign in to comment.