Skip to content

Commit

Permalink
fix(ecs): search through whole list of tasks for vpc ID (#3886) (#3902)
Browse files Browse the repository at this point in the history
  • Loading branch information
spinnakerbot authored and ezimanyi committed Jul 25, 2019
1 parent a4ba5d3 commit e44f8ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,6 @@ private EcsServerGroup buildEcsServerGroup(
Set<String> securityGroups = new HashSet<>();

if (!instances.isEmpty()) {
String taskId = instances.iterator().next().getName();
String taskKey = Keys.getTaskKey(account, region, taskId);
Task task = taskCacheClient.get(taskKey);

com.amazonaws.services.ec2.model.Instance ec2Instance =
containerInformationService.getEc2Instance(account, region, task);

if (eniSubnets != null
&& !eniSubnets.isEmpty()
&& eniSecurityGroups != null
Expand All @@ -340,12 +333,25 @@ private EcsServerGroup buildEcsServerGroup(

vpcId = vpcIds.iterator().next();
}
} else if (ec2Instance != null) {
vpcId = ec2Instance.getVpcId();
securityGroups =
ec2Instance.getSecurityGroups().stream()
.map(GroupIdentifier::getGroupId)
.collect(Collectors.toSet());
} else {
for (Instance instance : instances) {
String taskId = instance.getName();
String taskKey = Keys.getTaskKey(account, region, taskId);
Task task = taskCacheClient.get(taskKey);

if (task != null) {
com.amazonaws.services.ec2.model.Instance ec2Instance =
containerInformationService.getEc2Instance(account, region, task);
if (ec2Instance != null) {
vpcId = ec2Instance.getVpcId();
securityGroups =
ec2Instance.getSecurityGroups().stream()
.map(GroupIdentifier::getGroupId)
.collect(Collectors.toSet());
break;
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class EcsServerClusterProviderSpec extends Specification {
cacheView.filterIdentifiers(_, _) >> ['key']
cacheView.getAll(Keys.Namespace.SERVICES.ns, _) >> [serviceCacheData, serviceCacheData2]
cacheView.getAll(Keys.Namespace.TASKS.ns, _) >> [taskCacheData]
cacheView.get(Keys.Namespace.TASKS.ns, _) >> taskCacheData
}

def 'should produce an ecs cluster'() {
Expand Down

0 comments on commit e44f8ed

Please sign in to comment.