Skip to content

Commit 473dac4

Browse files
committed
Progagating Container Instance and Task Tags to Task Metadata endpoint; Bumping functional test timeout from 30m to 32m
1 parent de3eeb2 commit 473dac4

File tree

25 files changed

+680
-123
lines changed

25 files changed

+680
-123
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ test-in-docker:
193193
docker run --net=none -v "$(PWD):/go/src/github.com/aws/amazon-ecs-agent" --privileged "amazon/amazon-ecs-agent-test:make"
194194

195195
run-functional-tests: testnnp test-registry ecr-execution-role-image telemetry-test-image
196-
. ./scripts/shared_env && go test -tags functional -timeout=30m -v ./agent/functional_tests/...
196+
. ./scripts/shared_env && go test -tags functional -timeout=32m -v ./agent/functional_tests/...
197197

198198
.PHONY: build-image-for-ecr ecr-execution-role-image-for-upload upload-images replicate-images
199199

agent/api/ecsclient/client.go

+10
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,13 @@ func (client *APIECSClient) discoverPollEndpoint(containerInstanceArn string) (*
523523
client.pollEndpoinCache.Set(containerInstanceArn, output)
524524
return output, nil
525525
}
526+
527+
func (client *APIECSClient) GetResourceTags(resourceArn string) ([]*ecs.Tag, error) {
528+
output, err := client.standardClient.ListTagsForResource(&ecs.ListTagsForResourceInput{
529+
ResourceArn: &resourceArn,
530+
})
531+
if err != nil {
532+
return nil, err
533+
}
534+
return output.Tags, nil
535+
}

agent/api/interface.go

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type ECSClient interface {
4040
// DiscoverTelemetryEndpoint takes a ContainerInstanceARN and returns the
4141
// endpoint at which this Agent should contact Telemetry Service
4242
DiscoverTelemetryEndpoint(containerInstanceArn string) (string, error)
43+
// GetTaskTags retrieves the Tags associated with a certain Task
44+
GetResourceTags(resourceArn string) ([]*ecs.Tag, error)
4345
}
4446

4547
// ECSSDK is an interface that specifies the subset of the AWS Go SDK's ECS
@@ -49,6 +51,7 @@ type ECSSDK interface {
4951
CreateCluster(*ecs.CreateClusterInput) (*ecs.CreateClusterOutput, error)
5052
RegisterContainerInstance(*ecs.RegisterContainerInstanceInput) (*ecs.RegisterContainerInstanceOutput, error)
5153
DiscoverPollEndpoint(*ecs.DiscoverPollEndpointInput) (*ecs.DiscoverPollEndpointOutput, error)
54+
ListTagsForResource(*ecs.ListTagsForResourceInput) (*ecs.ListTagsForResourceOutput, error)
5255
}
5356

5457
// ECSSubmitStateSDK is an interface with customized ecs client that

agent/api/mocks/api_mocks.go

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/app/agent.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func (agent *ecsAgent) startAsyncRoutines(
559559
statsEngine := stats.NewDockerStatsEngine(agent.cfg, agent.dockerClient, containerChangeEventStream)
560560

561561
// Start serving the endpoint to fetch IAM Role credentials and other task metadata
562-
go handlers.ServeTaskHTTPEndpoint(credentialsManager, state, agent.containerInstanceARN, agent.cfg, statsEngine, agent.availabilityZone)
562+
go handlers.ServeTaskHTTPEndpoint(credentialsManager, state, client, agent.containerInstanceARN, agent.cfg, statsEngine, agent.availabilityZone)
563563

564564
// Start sending events to the backend
565565
go eventhandler.HandleEngineEvents(taskEngine, client, taskHandler)

agent/ecs_client/model/api/api-2.json

+17-2
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,8 @@
777777
"attachments":{"shape":"Attachments"},
778778
"clientToken":{
779779
"shape":"String"
780-
}
780+
},
781+
"tags":{"shape":"Tags"}
781782
}
782783
},
783784
"ContainerInstanceStatus":{
@@ -1623,6 +1624,12 @@
16231624
"stringSetValue":{"shape":"StringList"}
16241625
}
16251626
},
1627+
"ResourceNotFoundException":{
1628+
"type":"structure",
1629+
"members":{
1630+
},
1631+
"exception":true
1632+
},
16261633
"Resources":{
16271634
"type":"list",
16281635
"member":{"shape":"Resource"}
@@ -1665,6 +1672,13 @@
16651672
"DAEMON"
16661673
]
16671674
},
1675+
"Scope":{
1676+
"type":"string",
1677+
"enum":[
1678+
"task",
1679+
"shared"
1680+
]
1681+
},
16681682
"Secret":{
16691683
"type":"structure",
16701684
"required":[
@@ -1940,7 +1954,8 @@
19401954
"launchType":{"shape":"LaunchType"},
19411955
"platformVersion":{"shape":"String"},
19421956
"attachments":{"shape":"Attachments"},
1943-
"healthStatus":{"shape":"HealthStatus"}
1957+
"healthStatus":{"shape":"HealthStatus"},
1958+
"tags":{"shape":"Tags"}
19441959
}
19451960
},
19461961
"TaskDefinition":{

agent/ecs_client/model/api/docs-2.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,16 @@
676676
"refs": {
677677
}
678678
},
679+
"ListTagsForResourceRequest": {
680+
"base": null,
681+
"refs": {
682+
}
683+
},
684+
"ListTagsForResourceResponse": {
685+
"base": null,
686+
"refs": {
687+
}
688+
},
679689
"ListTaskDefinitionFamiliesRequest": {
680690
"base": null,
681691
"refs": {
@@ -951,7 +961,13 @@
951961
"refs": {
952962
"CreateServiceRequest$schedulingStrategy": "<p>The scheduling strategy to use for the service. For more information, see <a href=\"http://docs.aws.amazon.com/AmazonECS/latest/developerguideecs_services.html\">Services</a>.</p> <p>There are two service scheduler strategies available:</p> <ul> <li> <p> <code>REPLICA</code>-The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions.</p> </li> <li> <p> <code>DAEMON</code>-The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. When using this strategy, there is no need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies.</p> <note> <p>Fargate tasks do not support the <code>DAEMON</code> scheduling strategy.</p> </note> </li> </ul>",
953963
"ListServicesRequest$schedulingStrategy": "<p>The scheduling strategy for services to list.</p>",
954-
"Service$schedulingStrategy": "<p>The scheduling strategy to use for the service. For more information, see <a href=\"http://docs.aws.amazon.com/AmazonECS/latest/developerguideecs_services.html\">Services</a>.</p> <p>There are two service scheduler strategies available:</p> <ul> <li> <p> <code>REPLICA</code>-The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions.</p> </li> <li> <p> <code>DAEMON</code>-The daemon scheduling strategy deploys exactly one task on each container instance in your cluster. When using this strategy, do not specify a desired number of tasks or any task placement strategies.</p> <note> <p>Fargate tasks do not support the <code>DAEMON</code> scheduling strategy.</p> </note> </li> </ul>"
964+
"Service$schedulingStrategy": "<p>The scheduling strategy to use for the service. For more information, see <a href=\"http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html\">Services</a>.</p> <p>There are two service scheduler strategies available:</p> <ul> <li> <p> <code>REPLICA</code>-The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions.</p> </li> <li> <p> <code>DAEMON</code>-The daemon scheduling strategy deploys exactly one task on each container instance in your cluster. When you are using this strategy, do not specify a desired number of tasks or any task placement strategies.</p> <note> <p>Fargate tasks do not support the <code>DAEMON</code> scheduling strategy.</p> </note> </li> </ul>"
965+
}
966+
},
967+
"Scope": {
968+
"base": null,
969+
"refs": {
970+
"DockerVolumeConfiguration$scope": "<p>The scope for the Docker volume that determines its lifecycle. Docker volumes that are scoped to a <code>task</code> are automatically provisioned when the task starts and destroyed when the task stops. Docker volumes that are scoped as <code>shared</code> persist after the task stops.</p>"
955971
}
956972
},
957973
"Secret": {
@@ -1130,6 +1146,7 @@
11301146
"ListServicesRequest$cluster": "<p>The short name or full Amazon Resource Name (ARN) of the cluster that hosts the services to list. If you do not specify a cluster, the default cluster is assumed.</p>",
11311147
"ListServicesRequest$nextToken": "<p>The <code>nextToken</code> value returned from a previous paginated <code>ListServices</code> request where <code>maxResults</code> was used and the results exceeded the value of that parameter. Pagination continues from the end of the previous results that returned the <code>nextToken</code> value.</p> <note> <p>This token should be treated as an opaque identifier that is only used to retrieve the next items in a list and not for other programmatic purposes.</p> </note>",
11321148
"ListServicesResponse$nextToken": "<p>The <code>nextToken</code> value to include in a future <code>ListServices</code> request. When the results of a <code>ListServices</code> request exceed <code>maxResults</code>, this value can be used to retrieve the next page of results. This value is <code>null</code> when there are no more results to return.</p>",
1149+
"ListTagsForResourceRequest$resourceArn": "<p>The Amazon Resource Name (ARN) that identifies the resource for which to list the tags. Currently, the supported resources are Amazon ECS tasks, services, task definitions, clusters, and container instances.</p>",
11331150
"ListTaskDefinitionFamiliesRequest$familyPrefix": "<p>The <code>familyPrefix</code> is a string that is used to filter the results of <code>ListTaskDefinitionFamilies</code>. If you specify a <code>familyPrefix</code>, only task definition family names that begin with the <code>familyPrefix</code> string are returned.</p>",
11341151
"ListTaskDefinitionFamiliesRequest$nextToken": "<p>The <code>nextToken</code> value returned from a previous paginated <code>ListTaskDefinitionFamilies</code> request where <code>maxResults</code> was used and the results exceeded the value of that parameter. Pagination continues from the end of the previous results that returned the <code>nextToken</code> value.</p> <note> <p>This token should be treated as an opaque identifier that is only used to retrieve the next items in a list and not for other programmatic purposes.</p> </note>",
11351152
"ListTaskDefinitionFamiliesResponse$nextToken": "<p>The <code>nextToken</code> value to include in a future <code>ListTaskDefinitionFamilies</code> request. When the results of a <code>ListTaskDefinitionFamilies</code> request exceed <code>maxResults</code>, this value can be used to retrieve the next page of results. This value is <code>null</code> when there are no more results to return.</p>",
@@ -1294,6 +1311,14 @@
12941311
"refs": {
12951312
}
12961313
},
1314+
"Tags": {
1315+
"base": null,
1316+
"refs": {
1317+
"ContainerInstance$tags": "<p>The metadata that you apply to the container instance to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Tag keys can have a maximum character length of 128 characters, and tag values can have a maximum length of 256 characters.</p>",
1318+
"ListTagsForResourceResponse$tags": "<p>The tags for the resource.</p>",
1319+
"Task$tags": "<p>The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. Tag keys can have a maximum character length of 128 characters, and tag values can have a maximum length of 256 characters.</p>"
1320+
}
1321+
},
12971322
"TargetNotFoundException": {
12981323
"base": "<p>The specified target could not be found. You can view your available container instances with <a>ListContainerInstances</a>. Amazon ECS container instances are cluster-specific and region-specific.</p>",
12991324
"refs": {

agent/ecs_client/model/ecs/api.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -4939,6 +4939,12 @@ type ContainerInstance struct {
49394939
// in the Amazon Elastic Container Service Developer Guide.
49404940
Status *string `locationName:"status" type:"string"`
49414941

4942+
// The metadata that you apply to the container instance to help you categorize
4943+
// and organize them. Each tag consists of a key and an optional value, both
4944+
// of which you define. Tag keys can have a maximum character length of 128
4945+
// characters, and tag values can have a maximum length of 256 characters.
4946+
Tags []*Tag `locationName:"tags" type:"list"`
4947+
49424948
// The version counter for the container instance. Every time a container instance
49434949
// experiences a change that triggers a CloudWatch event, the version counter
49444950
// is incremented. If you are replicating your Amazon ECS container instance
@@ -5041,6 +5047,12 @@ func (s *ContainerInstance) SetStatus(v string) *ContainerInstance {
50415047
return s
50425048
}
50435049

5050+
// SetTags sets the Tags field's value.
5051+
func (s *ContainerInstance) SetTags(v []*Tag) *ContainerInstance {
5052+
s.Tags = v
5053+
return s
5054+
}
5055+
50445056
// SetVersion sets the Version field's value.
50455057
func (s *ContainerInstance) SetVersion(v int64) *ContainerInstance {
50465058
s.Version = &v
@@ -6678,6 +6690,10 @@ type DockerVolumeConfiguration struct {
66786690

66796691
Labels map[string]*string `locationName:"labels" type:"map"`
66806692

6693+
// The scope for the Docker volume that determines its lifecycle. Docker volumes
6694+
// that are scoped to a task are automatically provisioned when the task starts
6695+
// and destroyed when the task stops. Docker volumes that are scoped as shared
6696+
// persist after the task stops.
66816697
Scope *string `locationName:"scope" type:"string" enum:"Scope"`
66826698
}
66836699

@@ -7597,6 +7613,10 @@ func (s *ListServicesOutput) SetServiceArns(v []*string) *ListServicesOutput {
75977613
type ListTagsForResourceInput struct {
75987614
_ struct{} `type:"structure"`
75997615

7616+
// The Amazon Resource Name (ARN) that identifies the resource for which to
7617+
// list the tags. Currently, the supported resources are Amazon ECS tasks, services,
7618+
// task definitions, clusters, and container instances.
7619+
//
76007620
// ResourceArn is a required field
76017621
ResourceArn *string `locationName:"resourceArn" type:"string" required:"true"`
76027622
}
@@ -7633,6 +7653,7 @@ func (s *ListTagsForResourceInput) SetResourceArn(v string) *ListTagsForResource
76337653
type ListTagsForResourceOutput struct {
76347654
_ struct{} `type:"structure"`
76357655

7656+
// The tags for the resource.
76367657
Tags []*Tag `locationName:"tags" type:"list"`
76377658
}
76387659

@@ -9564,7 +9585,7 @@ type Service struct {
95649585
RunningCount *int64 `locationName:"runningCount" type:"integer"`
95659586

95669587
// The scheduling strategy to use for the service. For more information, see
9567-
// Services (http://docs.aws.amazon.com/AmazonECS/latest/developerguideecs_services.html).
9588+
// Services (http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html).
95689589
//
95699590
// There are two service scheduler strategies available:
95709591
//
@@ -9574,8 +9595,8 @@ type Service struct {
95749595
// and constraints to customize task placement decisions.
95759596
//
95769597
// * DAEMON-The daemon scheduling strategy deploys exactly one task on each
9577-
// container instance in your cluster. When using this strategy, do not specify
9578-
// a desired number of tasks or any task placement strategies.
9598+
// container instance in your cluster. When you are using this strategy,
9599+
// do not specify a desired number of tasks or any task placement strategies.
95799600
//
95809601
// Fargate tasks do not support the DAEMON scheduling strategy.
95819602
SchedulingStrategy *string `locationName:"schedulingStrategy" type:"string" enum:"SchedulingStrategy"`
@@ -10591,6 +10612,12 @@ type Task struct {
1059110612
// state to STOPPED).
1059210613
StoppingAt *time.Time `locationName:"stoppingAt" type:"timestamp"`
1059310614

10615+
// The metadata that you apply to the task to help you categorize and organize
10616+
// them. Each tag consists of a key and an optional value, both of which you
10617+
// define. Tag keys can have a maximum character length of 128 characters, and
10618+
// tag values can have a maximum length of 256 characters.
10619+
Tags []*Tag `locationName:"tags" type:"list"`
10620+
1059410621
// The Amazon Resource Name (ARN) of the task.
1059510622
TaskArn *string `locationName:"taskArn" type:"string"`
1059610623

@@ -10760,6 +10787,12 @@ func (s *Task) SetStoppingAt(v time.Time) *Task {
1076010787
return s
1076110788
}
1076210789

10790+
// SetTags sets the Tags field's value.
10791+
func (s *Task) SetTags(v []*Tag) *Task {
10792+
s.Tags = v
10793+
return s
10794+
}
10795+
1076310796
// SetTaskArn sets the TaskArn field's value.
1076410797
func (s *Task) SetTaskArn(v string) *Task {
1076510798
s.TaskArn = &v

agent/engine/dockerstate/docker_task_engine_state.go

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type TaskEngineState interface {
7373
DockerIDByV3EndpointID(v3EndpointID string) (string, bool)
7474
// TaskARNByV3EndpointID returns a taskARN for a given v3 endpoint ID
7575
TaskARNByV3EndpointID(v3EndpointID string) (string, bool)
76+
7677
json.Marshaler
7778
json.Unmarshaler
7879
}

agent/functional_tests/testdata/taskdefinitions/taskmetadata-validator-awsvpc/task-definition.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"retries": 2,
1313
"startPeriod": 1
1414
},
15+
"command": ["$$$CHECK_TAGS$$$"],
1516
"logConfiguration": {
1617
"logDriver": "awslogs",
1718
"options": {

agent/functional_tests/testdata/taskdefinitions/v3-task-endpoint-validator-windows/task-definition.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"startPeriod": 1
1414
},
1515
"entryPoint": ["powershell"],
16-
"command": [".\\application.ps1; $env:AWS_REGION=\"$$$TEST_REGION$$$\";.\\v3-task-endpoint-validator-windows.exe; exit $LASTEXITCODE"],
16+
"command": [".\\application.ps1; $env:AWS_REGION=\"$$$TEST_REGION$$$\";.\\v3-task-endpoint-validator-windows.exe $$$CHECK_TAGS$$$; exit $LASTEXITCODE"],
1717
"logConfiguration": {
1818
"logDriver": "awslogs",
1919
"options": {

agent/functional_tests/testdata/taskdefinitions/v3-task-endpoint-validator/task-definition.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"retries": 2,
1313
"startPeriod": 1
1414
},
15+
"command": ["$$$CHECK_TAGS$$$"],
1516
"logConfiguration": {
1617
"logDriver": "awslogs",
1718
"options": {

0 commit comments

Comments
 (0)