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

Fixes a bug where subnets were not constrained by zone #472

Merged
merged 1 commit into from
Jun 22, 2021
Merged
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
15 changes: 15 additions & 0 deletions pkg/cloudprovider/aws/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (s *SubnetProvider) Get(ctx context.Context, provisioner *v1alpha1.Provisio
if tagKey := constraints.GetSubnetTagKey(); tagKey != nil {
subnets = filter(byTagKey(*tagKey), subnets)
}
// 4. Filter by zones if constrained
if len(constraints.Zones) != 0 {
subnets = filter(byZones(constraints.Zones), subnets)
}
return subnets, nil
}

Expand Down Expand Up @@ -102,3 +106,14 @@ func byTagKey(tagKey string) func(*ec2.Subnet) bool {
return false
}
}

func byZones(zones []string) func(*ec2.Subnet) bool {
return func(subnet *ec2.Subnet) bool {
for _, zone := range zones {
if aws.StringValue(subnet.AvailabilityZone) == zone {
return true
}
}
return false
}
}