Skip to content

Conversation

@shogondo
Copy link

@shogondo shogondo commented Oct 2, 2025

Summary

This change introduces new environment variable ECS_PAUSE_LABELS. This can be used to apply custom labels to pause containers. Related issue: #4427.

Implementation details

Changes:

  • Update task.DockerConfig to apply custom labels to pause containers if the ECS_PAUSE_LABELS provided.
    • ECS_PAUSE_LABELS can be specified with JSON format, similar to ECS_AGENT_LABELS
    • If ECS_PAUSE_LABELS isn't provided, does nothing.
    • If ECS_PAUSE_LABELS is invalid format, just ignores it.

Testing

Tested manually on an EC2 container instance.

Config:

$ cat /etc/ecs/ecs.config
ECS_CLUSTER=my-sample
ECS_PAUSE_LABELS={"test.label":"hello world"}
ECS_AGENT_LABELS={"mylabel.1":"value1","mylabel.2":"value2"}

Before:

$ docker inspect CONTAINER_ID | jq .[0].Config.Labels
{
  "com.amazonaws.ecs.cluster": "my-sample",
  "com.amazonaws.ecs.container-name": "~internal~ecs~pause",
  ...
}

After:

$ docker inspect CONTAINER_ID | jq .[0].Config.Labels
{
  "com.amazonaws.ecs.cluster": "my-sample",
  "com.amazonaws.ecs.container-name": "~internal~ecs~pause",
  ...
  "test.label": "hello world"
}

New tests cover the changes: yes

Description for the changelog

Enhancement: Add new environment variable ECS_PAUSE_LABELS to apply custom labels to pause containers

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions?

Does this PR include the addition of new environment variables in the README?

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@shogondo shogondo requested a review from a team as a code owner October 2, 2025 01:41
@danehlim danehlim force-pushed the feature/pause-container-labels branch 2 times, most recently from 47d0aba to 282864b Compare November 1, 2025 04:14
@danehlim
Copy link
Contributor

danehlim commented Nov 1, 2025

Thank you @shogondo for your contribution with this pull request! I have made some updates to this pull request to address the comments I raised and will get this pull request reviewed by another member of our team.

@danehlim danehlim force-pushed the feature/pause-container-labels branch from 282864b to 660e68b Compare November 1, 2025 04:26
@danehlim danehlim linked an issue Nov 5, 2025 that may be closed by this pull request
switch container.Type {
case apicontainer.ContainerCNIPause, apicontainer.ContainerNamespacePause:
if pauseLabels := os.Getenv(pauseLabelsEnvVar); pauseLabels != "" {
// Set labels to pause container if it's provieded as env var.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: typo in provided

}

// Parse label string and set them to the given container configuration.
func setLabelsFromJsonString(config *dockercontainer.Config, labelsString string) {
Copy link
Contributor

@harishxr harishxr Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: rename function to setLabelsFromJSONString to be consistent with Go conventions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is not exported so we can keep it as is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im referring to Json -> JSON

return
}
if len(labels) > 0 {
config.Labels = labels
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where config.Labels is already defined, this line will overwrite it.

Copy link
Contributor

@TheanLim TheanLim Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The containerConfig is defined at L1788, and later we unmarshall and update containerConfig at L1803. Not sure whether a pause container's container.DockerConfig.Config will contain any Labels information but perhaps it's better to be cautious here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specify Docker labels for the amazon/amazon-ecs-pause container

5 participants