Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func deployService(ctx log.Interface, cluster, imageTag string, imageTags []stri
RequiresCompatibilities: taskDefinition.Compatibilities,
TaskRoleArn: taskDefinition.TaskRoleArn,
Volumes: taskDefinition.Volumes,
Tags: describeTaskResult.Tags,
Tags: nilIfEmpty(describeTaskResult.Tags),
})
if err != nil {
ctx.WithError(err).Error("Can't register task definition")
Expand Down
10 changes: 5 additions & 5 deletions lib/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
// RunTask runs the specified one-off task in the cluster using the task definition
func RunTask(profile, cluster, service, taskDefinitionName, imageTag string, imageTags []string, workDir, containerName, awslogGroup, launchType string, args []string) (exitCode int, err error) {
ctx := log.WithFields(log.Fields{
"task_definition": taskDefinitionName,
"launch_type": launchType,
})
"task_definition": taskDefinitionName,
"launch_type": launchType,
})
err = makeSession(profile)
if err != nil {
return 1, err
}

svc := ecs.New(localSession)

describeResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
Expand Down Expand Up @@ -68,7 +68,7 @@ func RunTask(profile, cluster, service, taskDefinitionName, imageTag string, ima
RequiresCompatibilities: taskDefinition.Compatibilities,
TaskRoleArn: taskDefinition.TaskRoleArn,
Volumes: taskDefinition.Volumes,
Tags: describeResult.Tags,
Tags: nilIfEmpty(describeResult.Tags),
})
if err != nil {
ctx.WithError(err).Error("Can't register task definition")
Expand Down
2 changes: 1 addition & 1 deletion lib/runFargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func RunFargate(profile, cluster, service, taskDefinitionName, imageTag string,
RequiresCompatibilities: taskDefinition.Compatibilities,
TaskRoleArn: taskDefinition.TaskRoleArn,
Volumes: taskDefinition.Volumes,
Tags: describeResult.Tags,
Tags: nilIfEmpty(describeResult.Tags),
})
if err != nil {
ctx.WithError(err).Error("Can't register task definition")
Expand Down
10 changes: 10 additions & 0 deletions lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,13 @@ func fetchSecurityGroupsByName(svc *ec2.EC2, securityGroupFilter string) ([]*str
// Return the filtered list of security group IDs
return securityGroups, nil
}

// nilIfEmpty returns nil when tags is empty so AWS doesn't reject the call with
// "Tags can not be empty" — the AWS API rejects an empty Tags list at the wire level;
// passing nil omits the field entirely.
func nilIfEmpty(tags []*ecs.Tag) []*ecs.Tag {
if len(tags) == 0 {
return nil
}
return tags
}
15 changes: 15 additions & 0 deletions lib/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@ import (
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
)

var testdata = map[string]string{
"arn:aws:ecs:us-west-1:433844053624:task/scratchpower-staging/334083dd41c04b429cbf99ea7aeeef19": "334083dd41c04b429cbf99ea7aeeef19", // new longer
"arn:aws:ecs:ap-southeast-2:208168611618:task/0c5027c6-7bbd-476b-a534-adaf56760ca9": "0c5027c6-7bbd-476b-a534-adaf56760ca9", // old format
}

func TestNilIfEmpty(t *testing.T) {
if nilIfEmpty(nil) != nil {
t.Fatal("nil input should return nil")
}
if nilIfEmpty([]*ecs.Tag{}) != nil {
t.Fatal("empty slice should return nil")
}
tags := []*ecs.Tag{{Key: aws.String("env"), Value: aws.String("prod")}}
result := nilIfEmpty(tags)
if len(result) != 1 || aws.StringValue(result[0].Key) != "env" || aws.StringValue(result[0].Value) != "prod" {
t.Fatalf("non-empty slice should be returned unchanged, got %v", result)
}
}

func TestParseTaskUUID(t *testing.T) {
for testArn, uuid := range testdata {
if parsedUUID, err := parseTaskUUID(aws.String(testArn)); err != nil {
Expand Down
Loading