Skip to content

Commit

Permalink
Fix unable to fetch ECS taskset tags (pipe-cd#4605)
Browse files Browse the repository at this point in the history
Signed-off-by: khanhtc1202 <[email protected]>
  • Loading branch information
khanhtc1202 authored and sZma5a committed Nov 5, 2023
1 parent fa66bf9 commit 84409ae
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions pkg/app/piped/platformprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 84409ae

Please sign in to comment.