From d41e28fc36772cd8b55967bad98d97e4a0f7716a Mon Sep 17 00:00:00 2001 From: jeffreykoetsier <5791868+jeffreykoetsier@users.noreply.github.com> Date: Fri, 29 Sep 2017 16:56:03 +0200 Subject: [PATCH] Handle empty ECS Clusters properly --- provider/ecs/ecs.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/provider/ecs/ecs.go b/provider/ecs/ecs.go index e48ebe5bc..32e9af5c6 100644 --- a/provider/ecs/ecs.go +++ b/provider/ecs/ecs.go @@ -214,7 +214,6 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types // Find all running Provider tasks in a cluster, also collect the task definitions (for docker labels) // and the EC2 instance data func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsInstance, error) { - var taskArns []*string var instances []ecsInstance var clustersArn []*string var clusters Clusters @@ -255,6 +254,8 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI DesiredStatus: aws.String(ecs.DesiredStatusRunning), }) + var taskArns []*string + for ; req != nil; req = req.NextPage() { if err := wrapAws(ctx, req); err != nil { return nil, err @@ -263,12 +264,10 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI taskArns = append(taskArns, req.Data.(*ecs.ListTasksOutput).TaskArns...) } - // Early return: if we can't list tasks we have nothing to - // describe below - likely empty cluster/permissions are bad. This - // stops the AWS API from returning a 401 when you DescribeTasks - // with no input. + // Skip to the next cluster if there are no tasks found on + // this cluster. if len(taskArns) == 0 { - return []ecsInstance{}, nil + continue } chunkedTaskArns := p.chunkedTaskArns(taskArns)