Skip to content

Commit 63224ec

Browse files
committed
Added support for pid and ipc in ECS Params
1 parent d70e748 commit 63224ec

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ task_definition:
444444
task_size: // Required for running tasks with Fargate launch type
445445
cpu_limit: string
446446
mem_limit: string
447+
pid: string // Supported string values: task or host
448+
ipc: string // Supported string values: task, host, or none
447449
services:
448450
<service_name>:
449451
essential: boolean
@@ -533,6 +535,10 @@ Fields listed under `task_definition` correspond to fields that will be included
533535

534536
* `task_size` Contains two fields, CPU and Memory. These fields are required for launching tasks with Fargate launch type. See [the documentation on ECS Task Definition Parameters](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html) for more information.
535537

538+
* `pid` allows you to control the process namespace in which your containers run. Valid values are `task` or `host`. See the [ECS documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_definition_pidmode) for more information.
539+
540+
* `ipc` allows you to control the IPC resource namespace in which your containers run. Valid values are `task`, `host`, or `none`. See the [ECS documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_definition_ipcmode) for more information.
541+
536542
**Run Params**
537543
Fields listed under `run_params` are for values needed as options to API calls not related to a Task Definition, such as `compose up` (RunTask) and `compose service up` (CreateService).
538544
Currently, the only parameter supported under `run_params` is `network_configuration`. This is required to run tasks with [Task Networking](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html), as well as with Fargate launch type.

ecs-cli/modules/cli/compose/entity/entity_helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ func createRegisterTaskDefinitionRequest(taskDefinition *ecs.TaskDefinition) *ec
123123
TaskRoleArn: taskDefinition.TaskRoleArn,
124124
RequiresCompatibilities: taskDefinition.RequiresCompatibilities,
125125
ExecutionRoleArn: taskDefinition.ExecutionRoleArn,
126+
PidMode: taskDefinition.PidMode,
127+
IpcMode: taskDefinition.IpcMode,
126128
}
127129

128130
if networkMode := taskDefinition.NetworkMode; aws.StringValue(networkMode) != "" {

ecs-cli/modules/utils/compose/convert_task_definition.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type TaskDefParams struct {
3434
taskRoleArn string
3535
cpu string
3636
memory string
37+
pidMode string
38+
ipcMode string
3739
containerDefs ContainerDefs
3840
executionRoleArn string
3941
}
@@ -123,6 +125,7 @@ func ConvertToTaskDefinition(params ConvertTaskDefParams) (*ecs.TaskDefinition,
123125
}
124126
}
125127

128+
// Note: this is later converted into an ecs.RegisterTaskDefinitionInput in entity_helper.go
126129
taskDefinition := &ecs.TaskDefinition{
127130
Family: aws.String(params.TaskDefName),
128131
ContainerDefinitions: containerDefinitions,
@@ -131,14 +134,15 @@ func ConvertToTaskDefinition(params ConvertTaskDefParams) (*ecs.TaskDefinition,
131134
NetworkMode: aws.String(taskDefParams.networkMode),
132135
Cpu: aws.String(taskDefParams.cpu),
133136
Memory: aws.String(taskDefParams.memory),
137+
PidMode: aws.String(taskDefParams.pidMode),
138+
IpcMode: aws.String(taskDefParams.ipcMode),
134139
ExecutionRoleArn: aws.String(executionRoleArn),
135140
}
136141

137142
// Set launch type
138143
if params.RequiredCompatibilites != "" {
139144
taskDefinition.RequiresCompatibilities = []*string{aws.String(params.RequiredCompatibilites)}
140145
}
141-
142146
return taskDefinition, nil
143147
}
144148

@@ -449,6 +453,8 @@ func convertTaskDefParams(ecsParams *ECSParams) (params TaskDefParams, e error)
449453
params.cpu = taskDef.TaskSize.Cpu
450454
params.memory = taskDef.TaskSize.Memory
451455
params.executionRoleArn = taskDef.ExecutionRole
456+
params.ipcMode = taskDef.IPC
457+
params.pidMode = taskDef.PID
452458

453459
return params, nil
454460
}

ecs-cli/modules/utils/compose/convert_task_definition_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,43 @@ func TestMemReservationHigherThanMemLimit(t *testing.T) {
12011201
assert.EqualError(t, err, "mem_limit must be greater than mem_reservation")
12021202
}
12031203

1204+
func TestConvertToTaskDefinitionWithECSParams_PIDandIPC(t *testing.T) {
1205+
containerConfig := &adapter.ContainerConfig{
1206+
Name: "web",
1207+
Image: "httpd",
1208+
}
1209+
1210+
ecsParamsString := `version: 1
1211+
task_definition:
1212+
pid: task
1213+
ipc: host`
1214+
1215+
content := []byte(ecsParamsString)
1216+
1217+
tmpfile, err := ioutil.TempFile("", "ecs-params")
1218+
assert.NoError(t, err, "Could not create ecs params tempfile")
1219+
1220+
defer os.Remove(tmpfile.Name())
1221+
1222+
_, err = tmpfile.Write(content)
1223+
assert.NoError(t, err, "Could not write data to ecs params tempfile")
1224+
1225+
err = tmpfile.Close()
1226+
assert.NoError(t, err, "Could not close tempfile")
1227+
1228+
ecsParamsFileName := tmpfile.Name()
1229+
ecsParams, err := ReadECSParams(ecsParamsFileName)
1230+
assert.NoError(t, err, "Could not read ECS Params file")
1231+
1232+
containerConfigs := []adapter.ContainerConfig{*containerConfig}
1233+
taskDefinition, err := convertToTaskDefinitionForTest(t, containerConfigs, "", "", ecsParams, nil)
1234+
1235+
if assert.NoError(t, err) {
1236+
assert.Equal(t, "task", aws.StringValue(taskDefinition.PidMode))
1237+
assert.Equal(t, "host", aws.StringValue(taskDefinition.IpcMode))
1238+
}
1239+
}
1240+
12041241
func TestConvertToTaskDefinitionWithVolumes(t *testing.T) {
12051242
volumeConfigs := &adapter.Volumes{
12061243
VolumeWithHost: map[string]string{

ecs-cli/modules/utils/compose/ecs_params_reader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type ECSParams struct {
4545
type EcsTaskDef struct {
4646
NetworkMode string `yaml:"ecs_network_mode"`
4747
TaskRoleArn string `yaml:"task_role_arn"`
48+
PID string `yaml:"pid"`
49+
IPC string `yaml:"ipc"`
4850
ContainerDefinitions ContainerDefs `yaml:"services"`
4951
ExecutionRole string `yaml:"task_execution_role"`
5052
TaskSize TaskSize `yaml:"task_size"` // Needed to run FARGATE tasks

ecs-cli/modules/utils/compose/ecs_params_reader_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,34 @@ task_definition:
356356
}
357357
}
358358

359+
func TestReadECSParams_WithPIDandIPC(t *testing.T) {
360+
ecsParamsString := `version: 1
361+
task_definition:
362+
pid: host
363+
ipc: task`
364+
365+
content := []byte(ecsParamsString)
366+
367+
tmpfile, err := ioutil.TempFile("", "ecs-params")
368+
assert.NoError(t, err, "Could not create ecs-params tempfile")
369+
370+
ecsParamsFileName := tmpfile.Name()
371+
defer os.Remove(ecsParamsFileName)
372+
373+
_, err = tmpfile.Write(content)
374+
assert.NoError(t, err, "Could not write data to ecs-params tempfile")
375+
376+
err = tmpfile.Close()
377+
assert.NoError(t, err, "Could not close tempfile")
378+
379+
ecsParams, err := ReadECSParams(ecsParamsFileName)
380+
381+
if assert.NoError(t, err) {
382+
assert.Equal(t, "host", ecsParams.TaskDefinition.PID, "Expected PID to be set")
383+
assert.Equal(t, "task", ecsParams.TaskDefinition.IPC, "Expected IPC to be set")
384+
}
385+
}
386+
359387
/** ConvertToECSNetworkConfiguration tests **/
360388

361389
func TestConvertToECSNetworkConfiguration(t *testing.T) {

0 commit comments

Comments
 (0)