Skip to content

Commit

Permalink
Fix deployment rollbacking with more than 100 tasks
Browse files Browse the repository at this point in the history
The `list_tasks` call was capped at 100 tasks, if your service had a desired
superior of 100 the deployment would fail.

Signed-off-by: Adrien Fillon <adrien.fillon@manomano.com>
  • Loading branch information
adrien-f committed Jul 19, 2021
1 parent 76f9cf0 commit 91cf91f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
16 changes: 10 additions & 6 deletions ecs_deploy/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import copy
from collections import defaultdict
import itertools
import logging
import click_log

Expand Down Expand Up @@ -71,10 +72,13 @@ def describe_task_definition(self, task_definition_arn):
)

def list_tasks(self, cluster_name, service_name):
return self.boto.list_tasks(
cluster=cluster_name,
serviceName=service_name
)
tasks_paginator = self.boto.get_paginator(u'list_tasks')
return list(itertools.chain.from_iterable(
res['taskArns'] for res in tasks_paginator.paginate(
cluster=cluster_name,
serviceName=service_name
)
))

def describe_tasks(self, cluster_name, task_arns):
return self.boto.describe_tasks(cluster=cluster_name, tasks=task_arns)
Expand Down Expand Up @@ -1173,11 +1177,11 @@ def is_deployed(self, service):
cluster_name=service.cluster,
service_name=service.name
)
if not running_tasks[u'taskArns']:
if not running_tasks:
return service.desired_count == 0
running_count = self.get_running_tasks_count(
service=service,
task_arns=running_tasks[u'taskArns']
task_arns=running_tasks
)
return service.desired_count == running_count

Expand Down
14 changes: 4 additions & 10 deletions tests/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,11 @@
u'test-task': RESPONSE_TASK_DEFINITION_2,
}

RESPONSE_LIST_TASKS_2 = {
u"taskArns": [TASK_ARN_1, TASK_ARN_2]
}
RESPONSE_LIST_TASKS_2 = [TASK_ARN_1, TASK_ARN_2]

RESPONSE_LIST_TASKS_1 = {
u"taskArns": [TASK_ARN_1]
}
RESPONSE_LIST_TASKS_1 = [TASK_ARN_1]

RESPONSE_LIST_TASKS_0 = {
u"taskArns": []
}
RESPONSE_LIST_TASKS_0 = []

RESPONSE_DESCRIBE_TASKS = {
u"tasks": [PAYLOAD_TASK_1, PAYLOAD_TASK_2]
Expand Down Expand Up @@ -1001,7 +995,7 @@ def test_client_describe_unknown_task_definition(client):

def test_client_list_tasks(client):
client.list_tasks(u'test-cluster', u'test-service')
client.boto.list_tasks.assert_called_once_with(cluster=u'test-cluster', serviceName=u'test-service')
client.boto.get_paginator.assert_called_once_with(u'list_tasks')


def test_client_describe_tasks(client):
Expand Down

0 comments on commit 91cf91f

Please sign in to comment.