Skip to content

Commit 51690e6

Browse files
committed
Do not overwrite any existing container config labels, update README, fix typo
1 parent 660e68b commit 51690e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ additional details about how to configure the agent.
259259
| `ECS_EBSTA_SUPPORTED` | `true` | Whether to use the container instance with EBS Task Attach support. This variable is set properly by ecs-init. Its value indicates if correct environment to support EBS volumes by instance has been set up or not. ECS only schedules EBSTA tasks if this feature is supported by the platform type. Check [EBS Volume considerations](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ebs-volumes.html#ebs-volume-considerations) for other EBS support details | `true` | Not Supported on Windows |
260260
| `ECS_ENABLE_FIRELENS_ASYNC` | `true` | Whether the log driver connects to the Firelens container in the background. | `true` | `true` |
261261
| `ECS_DETAILED_OS_FAMILY` | `debian_11` | Sets detailed OS information for Linux-based ECS instances by parsing /etc/os-release. This variable is set properly by ecs-init during system initialization. | `linux` | Not supported on Windows |
262+
| `ECS_PAUSE_LABELS` | `{"test.pause.label.1":"value1","test.pause.label.2":"value2"}` | The labels to add to the pause container. | | |
262263

263264
Additionally, the following environment variable(s) can be used to configure the behavior of the ecs-init service. When using ECS-Init, all env variables, including the ECS Agent variables above, are read from path `/etc/ecs/ecs.config`:
264265
| Environment Variable Name | Example Value(s) | Description | Default value |
@@ -267,7 +268,6 @@ Additionally, the following environment variable(s) can be used to configure the
267268
| `ECS_ALLOW_OFFHOST_INTROSPECTION_ACCESS` | <true | false> | By default, the ecs-init service adds an iptable rule to block access to ECS Agent's introspection port from off-host (or containers in awsvpc network mode), and removes the rule upon stop. If `ECS_ALLOW_OFFHOST_INTROSPECTION_ACCESS` is set to true, this rule will not be added/removed. | false |
268269
| `ECS_OFFHOST_INTROSPECTION_INTERFACE_NAME` | `eth0` | Primary network interface name to be used for blocking offhost agent introspection port access. By default, this value is `eth0` | `eth0` |
269270
| `ECS_AGENT_LABELS` | `{"test.label.1":"value1","test.label.2":"value2"}` | The labels to add to the ECS Agent container. | |
270-
| `ECS_PAUSE_LABELS` | `{"test.pause.label.1":"value1","test.pause.label.2":"value2"}` | The labels to add to the pause container. | |
271271
| `ECS_AGENT_APPARMOR_PROFILE` | `unconfined` | Specifies the name of the AppArmor profile to run the ecs-agent container under. This only applies to AppArmor-enabled systems, such as Ubuntu, Debian, and SUSE. If unset, defaults to the profile written out by ecs-init (ecs-agent-default). | `ecs-agent-default` |
272272
| `ECS_AGENT_PID_NAMESPACE_HOST` | <true | false> | By default, the ECS agent container runs with its own PID namespace. If ECS_AGENT_PID_NAMESPACE_HOST is set to true, ecs-init will start the ECS agent container with the host's PID namespace. This is particularly useful when running on SELinux-enforcing hosts with Docker's SELinux option enabled. | false |
273273

agent/api/task/task.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"sync"
2626
"time"
2727

28+
"maps"
29+
2830
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
2931
"github.com/aws/amazon-ecs-agent/agent/api/serviceconnect"
3032
"github.com/aws/amazon-ecs-agent/agent/config"
@@ -1817,8 +1819,8 @@ func (task *Task) dockerConfig(container *apicontainer.Container, apiVersion doc
18171819
switch container.Type {
18181820
case apicontainer.ContainerCNIPause, apicontainer.ContainerNamespacePause:
18191821
if pauseLabels := os.Getenv(pauseLabelsEnvVar); pauseLabels != "" {
1820-
// Set labels to pause container if it's provieded as env var.
1821-
setLabelsFromJsonString(containerConfig, pauseLabels)
1822+
// Set labels to pause container if it's provided as env var.
1823+
setLabelsFromJSONString(containerConfig, pauseLabels)
18221824
}
18231825
}
18241826

@@ -1831,7 +1833,8 @@ func (task *Task) dockerConfig(container *apicontainer.Container, apiVersion doc
18311833
}
18321834

18331835
// Parse label string and set them to the given container configuration.
1834-
func setLabelsFromJsonString(config *dockercontainer.Config, labelsString string) {
1836+
// This function is intended to only be used with container configuration whose `Labels` field is not nil.
1837+
func setLabelsFromJSONString(config *dockercontainer.Config, labelsString string) {
18351838
if len(labelsString) > 0 {
18361839
labels, err := commonutils.JsonBlockToStringToStringMap(labelsString)
18371840
if err != nil {
@@ -1841,7 +1844,7 @@ func setLabelsFromJsonString(config *dockercontainer.Config, labelsString string
18411844
return
18421845
}
18431846
if len(labels) > 0 {
1844-
config.Labels = labels
1847+
maps.Copy(config.Labels, labels)
18451848
}
18461849
}
18471850
}

0 commit comments

Comments
 (0)