Skip to content

Commit 355b6d8

Browse files
committed
Filter CNI subnets when creating EKS NodeGroup
1 parent 71d41d4 commit 355b6d8

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

api/v1beta2/network_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,17 @@ func (s Subnets) FilterPrivate() (res Subnets) {
510510
return
511511
}
512512

513+
// FilterNonCni returns the subnets that are NOT intended for usage with the CNI pod network
514+
// (i.e. do NOT have the `sigs.k8s.io/cluster-api-provider-aws/association=secondary` tag).
515+
func (s Subnets) FilterNonCni() (res Subnets) {
516+
for _, x := range s {
517+
if x.Tags[NameAWSSubnetAssociation] != SecondarySubnetTagValue {
518+
res = append(res, x)
519+
}
520+
}
521+
return
522+
}
523+
513524
// FilterPublic returns a slice containing all subnets marked as public.
514525
func (s Subnets) FilterPublic() (res Subnets) {
515526
for _, x := range s {

pkg/cloud/scope/shared.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (p *defaultSubnetPlacementStrategy) getSubnetsForAZs(azs []string, controlP
122122
subnets = subnets.FilterPublic()
123123
case expinfrav1.AZSubnetTypePrivate:
124124
subnets = subnets.FilterPrivate()
125+
subnets = subnets.FilterNonCni()
125126
}
126127
}
127128
if len(subnets) == 0 {

pkg/cloud/scope/shared_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ func TestSubnetPlacement(t *testing.T) {
182182
AvailabilityZone: "eu-west-1c",
183183
IsPublic: false,
184184
},
185+
infrav1.SubnetSpec{
186+
ID: "subnet-az6",
187+
AvailabilityZone: "eu-west-1c",
188+
IsPublic: false,
189+
Tags: infrav1.Tags{
190+
infrav1.NameAWSSubnetAssociation: infrav1.SecondarySubnetTagValue,
191+
},
192+
},
185193
},
186194
logger: logger.NewLogger(klog.Background()),
187195
expectedSubnetIDs: []string{"subnet-az3"},

0 commit comments

Comments
 (0)