From 2dbca13f60d50a4a89a44c3e591adcb0611274e3 Mon Sep 17 00:00:00 2001 From: adnan khan Date: Thu, 17 Oct 2019 15:36:11 -0400 Subject: [PATCH] api,config: rename unbounded memory config rename the unbounded memory config for windows and add update unit tests --- README.md | 2 +- agent/api/task/task_windows.go | 10 +++++----- agent/api/task/task_windows_test.go | 18 ++++++++---------- agent/config/config_windows.go | 11 ++++++----- agent/config/config_windows_test.go | 2 ++ agent/config/types_windows.go | 4 ++-- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 9fbceab7ac1..37ed13de30e 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ additional details on each available environment variable. | `ECS_CGROUP_PATH` | `/sys/fs/cgroup` | The root cgroup path that is expected by the ECS agent. This is the path that accessible from the agent mount. | `/sys/fs/cgroup` | Not applicable | | `ECS_CGROUP_CPU_PERIOD` | `10ms` | CGroups CPU period for task level limits. This value should be between 8ms to 100ms | `100ms` | Not applicable | | `ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will allow CPU unbounded(CPU=`0`) tasks to run along with CPU bounded tasks in Windows. | Not applicable | `false` | -| `ECS_ENABLE_RAM_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will allow tasks with no memory reservation to run along with memory bounded tasks in Windows. To run a memory unbounded task, omit the memory hard limit and set any memory reservation, it will be ignored. | Not applicable | `false` | +| `ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will ignore the memory reservation parameter (soft limit) to run along with memory bounded tasks in Windows. To run a memory unbounded task, omit the memory hard limit and set any memory reservation, it will be ignored. | Not applicable | `false` | | `ECS_TASK_METADATA_RPS_LIMIT` | `100,150` | Comma separated integer values for steady state and burst throttle limits for task metadata endpoint | `40,60` | `40,60` | | `ECS_SHARED_VOLUME_MATCH_FULL_CONFIG` | `true` | When `true`, ECS Agent will compare name, driver options, and labels to make sure volumes are identical. When `false`, Agent will short circuit shared volume comparison if the names match. This is the default Docker behavior. If a volume is shared across instances, this should be set to `false`. | `false` | `false`| | `ECS_CONTAINER_INSTANCE_PROPAGATE_TAGS_FROM` | `ec2_instance` | If `ec2_instance` is specified, existing tags defined on the container instance will be registered to Amazon ECS and will be discoverable using the `ListTagsForResource` API. Using this requires that the IAM role associated with the container instance have the `ec2:DescribeTags` action allowed. | `none` | `none` | diff --git a/agent/api/task/task_windows.go b/agent/api/task/task_windows.go index d96a6a473e9..8bb9e3f1775 100644 --- a/agent/api/task/task_windows.go +++ b/agent/api/task/task_windows.go @@ -42,9 +42,9 @@ type PlatformFields struct { // CpuUnbounded determines whether a mix of unbounded and bounded CPU tasks // are allowed to run in the instance CpuUnbounded bool `json:"cpuUnbounded"` - // RamUnbounded determines whether a mix of unbounded and bounded Memory tasks + // MemoryUnbounded determines whether a mix of unbounded and bounded Memory tasks // are allowed to run in the instance - RamUnbounded bool `json:"ramUnbounded"` + MemoryUnbounded bool `json:"memoryUnbounded"` } var cpuShareScaleFactor = runtime.NumCPU() * cpuSharesPerCore @@ -53,8 +53,8 @@ var cpuShareScaleFactor = runtime.NumCPU() * cpuSharesPerCore func (task *Task) adjustForPlatform(cfg *config.Config) { task.downcaseAllVolumePaths() platformFields := PlatformFields{ - CpuUnbounded: cfg.PlatformVariables.CPUUnbounded, - RamUnbounded: cfg.PlatformVariables.RAMUnbounded, + CpuUnbounded: cfg.PlatformVariables.CPUUnbounded, + MemoryUnbounded: cfg.PlatformVariables.MemoryUnbounded, } task.PlatformFields = platformFields } @@ -124,7 +124,7 @@ func (task *Task) platformHostConfigOverride(hostConfig *dockercontainer.HostCon } hostConfig.CPUShares = 0 - if hostConfig.Memory <= 0 && task.PlatformFields.RamUnbounded { + if hostConfig.Memory <= 0 && task.PlatformFields.MemoryUnbounded { // As of version 17.06.2-ee-6 of docker. MemoryReservation is not supported on windows. This ensures that // this parameter is not passed, allowing to launch a container without a hard limit. hostConfig.MemoryReservation = 0 diff --git a/agent/api/task/task_windows_test.go b/agent/api/task/task_windows_test.go index f143c6d1773..584431078eb 100644 --- a/agent/api/task/task_windows_test.go +++ b/agent/api/task/task_windows_test.go @@ -283,23 +283,21 @@ func TestWindowsMemoryReservationOption(t *testing.T) { }, }, PlatformFields: PlatformFields{ - RamUnbounded: false, + MemoryUnbounded: false, }, } - // With RamUnbounded set to false, MemoryReservation is not overridden + // With MemoryUnbounded set to false, MemoryReservation is not overridden config, configErr := testTask.DockerHostConfig(testTask.Containers[0], dockerMap(testTask), defaultDockerClientAPIVersion) - if configErr != nil { - t.Fatal(configErr) - } + + assert.Nil(t, configErr) assert.EqualValues(t, nonZeroMemoryReservationValue, config.MemoryReservation) - // With RamUnbounded set to true, tasks with no memory hard limit will have their memory reservation set to zero - testTask.PlatformFields.RamUnbounded = true + // With MemoryUnbounded set to true, tasks with no memory hard limit will have their memory reservation set to zero + testTask.PlatformFields.MemoryUnbounded = true config, configErr = testTask.DockerHostConfig(testTask.Containers[0], dockerMap(testTask), defaultDockerClientAPIVersion) - if configErr != nil { - t.Fatal(configErr) - } + + assert.Nil(t, configErr) assert.EqualValues(t, expectedMemoryReservationValue, config.MemoryReservation) } diff --git a/agent/config/config_windows.go b/agent/config/config_windows.go index 149a3e5870e..0e8bed016ab 100644 --- a/agent/config/config_windows.go +++ b/agent/config/config_windows.go @@ -58,8 +58,8 @@ func DefaultConfig() Config { ecsRoot := filepath.Join(programData, "Amazon", "ECS") dataDir := filepath.Join(ecsRoot, "data") platformVariables := PlatformVariables{ - CPUUnbounded: false, - RAMUnbounded: false, + CPUUnbounded: false, + MemoryUnbounded: false, } return Config{ DockerEndpoint: "npipe:////./pipe/docker_engine", @@ -119,10 +119,11 @@ func (cfg *Config) platformOverrides() { cfg.TaskCPUMemLimit = ExplicitlyDisabled cpuUnbounded := utils.ParseBool(os.Getenv("ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND"), false) - ramUnbounded := utils.ParseBool(os.Getenv("ECS_ENABLE_RAM_UNBOUNDED_WINDOWS_WORKAROUND"), false) + memoryUnbounded := utils.ParseBool(os.Getenv("ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND"), false) + platformVariables := PlatformVariables{ - CPUUnbounded: cpuUnbounded, - RAMUnbounded: ramUnbounded, + CPUUnbounded: cpuUnbounded, + MemoryUnbounded: memoryUnbounded, } cfg.PlatformVariables = platformVariables } diff --git a/agent/config/config_windows_test.go b/agent/config/config_windows_test.go index 4da165a0881..59ef1936739 100644 --- a/agent/config/config_windows_test.go +++ b/agent/config/config_windows_test.go @@ -59,6 +59,8 @@ func TestConfigDefault(t *testing.T) { assert.Equal(t, DefaultTaskMetadataBurstRate, cfg.TaskMetadataBurstRate, "Default TaskMetadataBurstRate is set incorrectly") assert.False(t, cfg.SharedVolumeMatchFullConfig, "Default SharedVolumeMatchFullConfig set incorrectly") + assert.False(t, cfg.CPUUnbounded, "ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND set incorrectly") + assert.False(t, cfg.MemoryUnbounded, "ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND set incorrectly") } func TestConfigIAMTaskRolesReserves80(t *testing.T) { diff --git a/agent/config/types_windows.go b/agent/config/types_windows.go index 8afe8b03b8c..9060db332bc 100644 --- a/agent/config/types_windows.go +++ b/agent/config/types_windows.go @@ -19,7 +19,7 @@ type PlatformVariables struct { // CPUUnbounded specifies if agent can run a mix of CPU bounded and // unbounded tasks for windows CPUUnbounded bool - // RAMUnbounded specifies if agent can run a mix of Memory bounded and + // MemoryUnbounded specifies if agent can run a mix of Memory bounded and // unbounded tasks for windows - RAMUnbounded bool + MemoryUnbounded bool }