Skip to content

Commit

Permalink
Constraint subnets based on zones (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekgogia authored Jun 22, 2021
1 parent e1d4251 commit 1e1ffc8
Showing 1 changed file with 15 additions and 0 deletions.
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
}
}

0 comments on commit 1e1ffc8

Please sign in to comment.