Handle empty ECS Clusters properly

This commit is contained in:
jeffreykoetsier 2017-09-29 16:56:03 +02:00 committed by Traefiker
parent 64c52a6921
commit d41e28fc36

View file

@ -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) // Find all running Provider tasks in a cluster, also collect the task definitions (for docker labels)
// and the EC2 instance data // and the EC2 instance data
func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsInstance, error) { func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsInstance, error) {
var taskArns []*string
var instances []ecsInstance var instances []ecsInstance
var clustersArn []*string var clustersArn []*string
var clusters Clusters var clusters Clusters
@ -255,6 +254,8 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI
DesiredStatus: aws.String(ecs.DesiredStatusRunning), DesiredStatus: aws.String(ecs.DesiredStatusRunning),
}) })
var taskArns []*string
for ; req != nil; req = req.NextPage() { for ; req != nil; req = req.NextPage() {
if err := wrapAws(ctx, req); err != nil { if err := wrapAws(ctx, req); err != nil {
return nil, err 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...) taskArns = append(taskArns, req.Data.(*ecs.ListTasksOutput).TaskArns...)
} }
// Early return: if we can't list tasks we have nothing to // Skip to the next cluster if there are no tasks found on
// describe below - likely empty cluster/permissions are bad. This // this cluster.
// stops the AWS API from returning a 401 when you DescribeTasks
// with no input.
if len(taskArns) == 0 { if len(taskArns) == 0 {
return []ecsInstance{}, nil continue
} }
chunkedTaskArns := p.chunkedTaskArns(taskArns) chunkedTaskArns := p.chunkedTaskArns(taskArns)