From b995a11d63938f749f8def9dc926702547acc955 Mon Sep 17 00:00:00 2001 From: Romain Date: Wed, 11 Jan 2023 15:14:05 +0100 Subject: [PATCH] Prevent panicking when a container has no network interfaces Co-authored-by: Kevin Pollet --- pkg/provider/ecs/ecs.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/provider/ecs/ecs.go b/pkg/provider/ecs/ecs.go index 1958723db..8def19a85 100644 --- a/pkg/provider/ecs/ecs.go +++ b/pkg/provider/ecs/ecs.go @@ -315,6 +315,11 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI var mach *machine if len(task.Attachments) != 0 { + if len(container.NetworkInterfaces) == 0 { + logger.Errorf("Skip container %s: no network interfaces", aws.StringValue(container.Name)) + continue + } + var ports []portMapping for _, mapping := range containerDefinition.PortMappings { if mapping != nil { @@ -378,7 +383,7 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI extraConf, err := p.getConfiguration(instance) if err != nil { - log.FromContext(ctx).Errorf("Skip container %s: %w", getServiceName(instance), err) + logger.Errorf("Skip container %s: %w", getServiceName(instance), err) continue } instance.ExtraConf = extraConf