Skip to content

Commit

Permalink
fix(amazon/loadBalancer): If multiple subnets in an az, pick the one …
Browse files Browse the repository at this point in the history
…with most ip space (#2493)
  • Loading branch information
Justin Reynolds committed Apr 6, 2018
1 parent 03912e2 commit f375f99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package com.netflix.spinnaker.clouddriver.aws.model
import com.amazonaws.services.ec2.model.Subnet
import com.google.common.base.Function
import com.google.common.base.Preconditions
import com.google.common.base.Supplier
import com.google.common.collect.ImmutableSet
import com.google.common.collect.Maps
import com.google.common.collect.Multimap
import com.google.common.collect.Multimaps
import groovy.transform.Canonical
Expand Down Expand Up @@ -68,12 +66,12 @@ class SubnetAnalyzer {
}
Map<String, Collection<SubnetData>> zonesToSubnets = mapZonesToTargetSubnets(target).asMap()
zonesToSubnets.subMap(zones).findResults { z, c ->
List<String> filtered = c.findResults { it.purpose == purpose ? it.subnetId : null }
List<SubnetData> filtered = c.findResults { it.purpose == purpose ? it : null }
if (maxSubnetsPerZone != null) {
Collections.shuffle(filtered)
return filtered.take(maxSubnetsPerZone)
filtered.sort { -it.availableIpAddressCount }
filtered = filtered.take(maxSubnetsPerZone)
}
return filtered
return filtered.collect { it.subnetId }
}.flatten()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import spock.lang.Specification
class SubnetAnalyzerSpec extends Specification {

static SubnetData subnet(String id, String zone, String purpose, SubnetTarget target, String vpcId = 'vpc-1') {
new SubnetData(subnetId: id, availabilityZone: zone, purpose: purpose, target: target, vpcId: vpcId)
new SubnetData(subnetId: id, availabilityZone: zone, purpose: purpose, target: target, vpcId: vpcId, availableIpAddressCount: 42)
}

static SecurityGroup securityGroup(String id, String vpcId = null) {
Expand Down

0 comments on commit f375f99

Please sign in to comment.