From 91f5590647a83afb5a323c13748a1f926cb930dc Mon Sep 17 00:00:00 2001 From: khanhtc1202 Date: Fri, 6 Oct 2023 15:31:23 +0700 Subject: [PATCH] Fix unable to fetch ECS taskset tags Signed-off-by: khanhtc1202 --- pkg/app/piped/platformprovider/ecs/client.go | 29 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/pkg/app/piped/platformprovider/ecs/client.go b/pkg/app/piped/platformprovider/ecs/client.go index 4dc80cfcfa..ef559e6e33 100644 --- a/pkg/app/piped/platformprovider/ecs/client.go +++ b/pkg/app/piped/platformprovider/ecs/client.go @@ -201,6 +201,7 @@ func (c *client) CreateTaskSet(ctx context.Context, service types.Service, taskD if taskDefinition.TaskDefinitionArn == nil { return nil, fmt.Errorf("failed to create task set of task family %s: no task definition provided", *taskDefinition.Family) } + input := &ecs.CreateTaskSetInput{ Cluster: service.ClusterArn, Service: service.ServiceArn, @@ -266,16 +267,38 @@ func (c *client) GetServiceTaskSets(ctx context.Context, service types.Service) return nil, fmt.Errorf("failed to get task sets of service %s: services empty", *service.ServiceName) } svc := output.Services[0] - taskSets := make([]*types.TaskSet, 0, len(svc.TaskSets)) + activeTaskSetArns := make([]string, 0, len(svc.TaskSets)) for i := range svc.TaskSets { if aws.ToString(svc.TaskSets[i].Status) == "DRAINING" { continue } - if !IsPipeCDManagedTaskSet(&svc.TaskSets[i]) { + activeTaskSetArns = append(activeTaskSetArns, *svc.TaskSets[i].TaskSetArn) + } + + if len(activeTaskSetArns) == 0 { + return nil, fmt.Errorf("failed to get task sets of service %s: services empty", *service.ServiceName) + } + + tsInput := &ecs.DescribeTaskSetsInput{ + Cluster: service.ClusterArn, + Service: service.ServiceArn, + TaskSets: activeTaskSetArns, + Include: []types.TaskSetField{ + types.TaskSetFieldTags, + }, + } + tsOutput, err := c.ecsClient.DescribeTaskSets(ctx, tsInput) + if err != nil { + return nil, fmt.Errorf("failed to get task sets of service %s: %w", *service.ServiceName, err) + } + taskSets := make([]*types.TaskSet, 0, len(tsOutput.TaskSets)) + for i := range tsOutput.TaskSets { + if !IsPipeCDManagedTaskSet(&tsOutput.TaskSets[i]) { continue } - taskSets = append(taskSets, &svc.TaskSets[i]) + taskSets = append(taskSets, &tsOutput.TaskSets[i]) } + return taskSets, nil }