Skip to content

Commit

Permalink
fix(ecs): Handle container instances no longer being cached, but show…
Browse files Browse the repository at this point in the history
…ing up in stopped ECS tasks in the account (#3765)

Fixes spinnaker/spinnaker#4466
  • Loading branch information
clareliguori authored and ezimanyi committed Jun 12, 2019
1 parent db7c7a1 commit a316ab9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private TaskHealth inferHealthNetworkBindedContainer(

for (LoadBalancer loadBalancer : loadBalancers) {
if (loadBalancer.getTargetGroupArn() == null
|| containerInstance == null
|| containerInstance.getEc2InstanceId() == null) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@ class TaskHealthCachingAgentSpec extends Specification {
taskHealth.getTaskId() == CommonCachingAgent.TASK_ID_1
}

def 'should skip tasks with a non-cached container instance'() {
given:
ObjectMapper mapper = new ObjectMapper()
Map<String, Object> containerMap = mapper.convertValue(new Container().withNetworkBindings(new NetworkBinding().withHostPort(1337)), Map.class)
def taskAttributes = [
taskId : CommonCachingAgent.TASK_ID_1,
taskArn : CommonCachingAgent.TASK_ARN_1,
startedAt : new Date().getTime(),
containerInstanceArn: CommonCachingAgent.CONTAINER_INSTANCE_ARN_2,
group : 'service:' + CommonCachingAgent.SERVICE_NAME_1,
containers : Collections.singletonList(containerMap)
]
def taskKey = Keys.getTaskKey(CommonCachingAgent.ACCOUNT, CommonCachingAgent.REGION, CommonCachingAgent.TASK_ID_1)
def taskCacheData = new DefaultCacheData(taskKey, taskAttributes, Collections.emptyMap())
providerCache.getAll(TASKS.toString(), _) >> Collections.singletonList(taskCacheData)

when:
def taskHealthList = agent.getItems(ecs, providerCache)

then:
taskHealthList == []
}

def 'should get a list of task health for aws-vpc mode'() {
given:
ObjectMapper mapper = new ObjectMapper()
Expand Down

0 comments on commit a316ab9

Please sign in to comment.