Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make create container timeout configurable #2781

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ additional details on each available environment variable.
| `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION` | 10m | Time to wait to delete containers for a stopped task. If set to less than 1 minute, the value is ignored. | 3h | 3h |
| `ECS_CONTAINER_STOP_TIMEOUT` | 10m | Instance scoped configuration for time to wait for the container to exit normally before being forcibly killed. | 30s | 30s |
| `ECS_CONTAINER_START_TIMEOUT` | 10m | Timeout before giving up on starting a container. | 3m | 8m |
| `ECS_CONTAINER_CREATE_TIMEOUT` | 10m | Timeout before giving up on creating a container. Minimum value is 1m. If user sets a value below minimum it will be set to min. | 4m | 4m |
| `ECS_ENABLE_TASK_IAM_ROLE` | `true` | Whether to enable IAM Roles for Tasks on the Container Instance | `false` | `false` |
| `ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST` | `true` | Whether to enable IAM Roles for Tasks when launched with `host` network mode on the Container Instance | `false` | `false` |
| `ECS_DISABLE_IMAGE_CLEANUP` | `true` | Whether to disable automated image cleanup for the ECS Agent. | `false` | `false` |
Expand Down
3 changes: 3 additions & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ func environmentConfig() (Config, error) {
TaskCPUMemLimit: parseBooleanDefaultTrueConfig("ECS_ENABLE_TASK_CPU_MEM_LIMIT"),
DockerStopTimeout: parseDockerStopTimeout(),
ContainerStartTimeout: parseContainerStartTimeout(),
ContainerCreateTimeout: parseContainerCreateTimeout(),
DependentContainersPullUpfront: parseBooleanDefaultFalseConfig("ECS_PULL_DEPENDENT_CONTAINERS_UPFRONT"),
ImagePullInactivityTimeout: parseImagePullInactivityTimeout(),
ImagePullTimeout: parseEnvVariableDuration("ECS_IMAGE_PULL_TIMEOUT"),
Expand Down Expand Up @@ -601,6 +602,7 @@ func (cfg *Config) String() string {
"TaskCleanupWaitDuration: %v, "+
"DockerStopTimeout: %v, "+
"ContainerStartTimeout: %v, "+
"ContainerCreateTimeout: %v, "+
"DependentContainersPullUpfront: %v, "+
"TaskCPUMemLimit: %v, "+
"%s",
Expand All @@ -617,6 +619,7 @@ func (cfg *Config) String() string {
cfg.TaskCleanupWaitDuration,
cfg.DockerStopTimeout,
cfg.ContainerStartTimeout,
cfg.ContainerCreateTimeout,
cfg.DependentContainersPullUpfront,
cfg.TaskCPUMemLimit,
cfg.platformString(),
Expand Down
27 changes: 27 additions & 0 deletions agent/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestEnvironmentConfig(t *testing.T) {
defer setTestEnv("ECS_RESERVED_MEMORY", "20")()
defer setTestEnv("ECS_CONTAINER_STOP_TIMEOUT", "60s")()
defer setTestEnv("ECS_CONTAINER_START_TIMEOUT", "5m")()
defer setTestEnv("ECS_CONTAINER_CREATE_TIMEOUT", "4m")()
defer setTestEnv("ECS_IMAGE_PULL_INACTIVITY_TIMEOUT", "10m")()
defer setTestEnv("ECS_AVAILABLE_LOGGING_DRIVERS", "[\""+string(dockerclient.SyslogDriver)+"\"]")()
defer setTestEnv("ECS_SELINUX_CAPABLE", "true")()
Expand Down Expand Up @@ -164,6 +165,8 @@ func TestEnvironmentConfig(t *testing.T) {
assert.Equal(t, expectedDurationDockerStopTimeout, conf.DockerStopTimeout)
expectedDurationContainerStartTimeout, _ := time.ParseDuration("5m")
assert.Equal(t, expectedDurationContainerStartTimeout, conf.ContainerStartTimeout)
expectedDurationContainerCreateTimeout, _ := time.ParseDuration("4m")
assert.Equal(t, expectedDurationContainerCreateTimeout, conf.ContainerCreateTimeout)
assert.Equal(t, []dockerclient.LoggingDriver{dockerclient.SyslogDriver}, conf.AvailableLoggingDrivers)
assert.True(t, conf.PrivilegedDisabled.Enabled())
assert.True(t, conf.SELinuxCapable.Enabled(), "Wrong value for SELinuxCapable")
Expand Down Expand Up @@ -322,6 +325,14 @@ func TestInvalidFormatContainerStartTimeout(t *testing.T) {
assert.Equal(t, defaultContainerStartTimeout, conf.ContainerStartTimeout, "Wrong value for ContainerStartTimeout")
}

func TestInvalidFormatContainerCreateTimeout(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_CONTAINER_CREATE_TIMEOUT", "invalid")()
conf, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
assert.NoError(t, err)
assert.Equal(t, defaultContainerCreateTimeout, conf.ContainerCreateTimeout, "Wrong value for ContainerCreateTimeout")
}

func TestInvalidFormatDockerInactivityTimeout(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_IMAGE_PULL_INACTIVITY_TIMEOUT", "invalid")()
Expand Down Expand Up @@ -355,6 +366,14 @@ func TestZeroValueContainerStartTimeout(t *testing.T) {
assert.Equal(t, defaultContainerStartTimeout, conf.ContainerStartTimeout, "Wrong value for ContainerStartTimeout")
}

func TestZeroValueContainerCreateTimeout(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_CONTAINER_CREATE_TIMEOUT", "0s")()
conf, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
assert.NoError(t, err)
assert.Equal(t, defaultContainerCreateTimeout, conf.ContainerCreateTimeout, "Wrong value for ContainerCreateTimeout")
}

func TestInvalidValueContainerStartTimeout(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_CONTAINER_START_TIMEOUT", "-10s")()
Expand All @@ -363,6 +382,14 @@ func TestInvalidValueContainerStartTimeout(t *testing.T) {
assert.Equal(t, minimumContainerStartTimeout, conf.ContainerStartTimeout, "Wrong value for ContainerStartTimeout")
}

func TestInvalidValueContainerCreateTimeout(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_CONTAINER_CREATE_TIMEOUT", "-10s")()
conf, err := NewConfig(ec2.NewBlackholeEC2MetadataClient())
assert.NoError(t, err)
assert.Equal(t, minimumContainerCreateTimeout, conf.ContainerCreateTimeout, "Wrong value for ContainerCreataeTimeout")
}

func TestZeroValueDockerPullInactivityTimeout(t *testing.T) {
defer setTestRegion()()
defer setTestEnv("ECS_DOCKER_PULL_INACTIVITY_TIMEOUT", "0s")()
Expand Down
5 changes: 5 additions & 0 deletions agent/config/config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const (
defaultContainerStartTimeout = 3 * time.Minute
// minimumContainerStartTimeout specifies the minimum value for starting a container
minimumContainerStartTimeout = 45 * time.Second
// defaultContainerCreateTimeout specifies the value for container create timeout duration
defaultContainerCreateTimeout = 4 * time.Minute
// minimumContainerCreateTimeout specifies the minimum value for creating a container
minimumContainerCreateTimeout = 1 * time.Minute
// default docker inactivity time is extra time needed on container extraction
defaultImagePullInactivityTimeout = 1 * time.Minute
)
Expand All @@ -56,6 +60,7 @@ func DefaultConfig() Config {
TaskCleanupWaitDuration: DefaultTaskCleanupWaitDuration,
DockerStopTimeout: defaultDockerStopTimeout,
ContainerStartTimeout: defaultContainerStartTimeout,
ContainerCreateTimeout: defaultContainerCreateTimeout,
DependentContainersPullUpfront: BooleanDefaultFalse{Value: ExplicitlyDisabled},
CredentialsAuditLogFile: defaultCredentialsAuditLogFile,
CredentialsAuditLogDisabled: false,
Expand Down
1 change: 1 addition & 0 deletions agent/config/config_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestConfigDefault(t *testing.T) {
assert.Equal(t, uint16(0), cfg.ReservedMemory, "Default reserved memory set incorrectly")
assert.Equal(t, 30*time.Second, cfg.DockerStopTimeout, "Default docker stop container timeout set incorrectly")
assert.Equal(t, 3*time.Minute, cfg.ContainerStartTimeout, "Default docker start container timeout set incorrectly")
assert.Equal(t, 4*time.Minute, cfg.ContainerCreateTimeout, "Default docker create container timeout set incorrectly")
assert.False(t, cfg.PrivilegedDisabled.Enabled(), "Default PrivilegedDisabled set incorrectly")
assert.Equal(t, []dockerclient.LoggingDriver{dockerclient.JSONFileDriver, dockerclient.NoneDriver},
cfg.AvailableLoggingDrivers, "Default logging drivers set incorrectly")
Expand Down
5 changes: 5 additions & 0 deletions agent/config/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const (
defaultContainerStartTimeout = 8 * time.Minute
// minimumContainerStartTimeout specifies the minimum value for starting a container
minimumContainerStartTimeout = 2 * time.Minute
// defaultContainerCreateTimeout specifies the value for container create timeout duration
defaultContainerCreateTimeout = 4 * time.Minute
// minimumContainerCreateTimeout specifies the minimum value for creating a container
minimumContainerCreateTimeout = 1 * time.Minute
// default image pull inactivity time is extra time needed on container extraction
defaultImagePullInactivityTimeout = 3 * time.Minute
)
Expand Down Expand Up @@ -86,6 +90,7 @@ func DefaultConfig() Config {
TaskCleanupWaitDuration: DefaultTaskCleanupWaitDuration,
DockerStopTimeout: defaultDockerStopTimeout,
ContainerStartTimeout: defaultContainerStartTimeout,
ContainerCreateTimeout: defaultContainerCreateTimeout,
DependentContainersPullUpfront: BooleanDefaultFalse{Value: ExplicitlyDisabled},
ImagePullInactivityTimeout: defaultImagePullInactivityTimeout,
ImagePullTimeout: DefaultImagePullTimeout,
Expand Down
1 change: 1 addition & 0 deletions agent/config/config_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestConfigDefault(t *testing.T) {
assert.Equal(t, uint16(0), cfg.ReservedMemory, "Default reserved memory set incorrectly")
assert.Equal(t, 30*time.Second, cfg.DockerStopTimeout, "Default docker stop container timeout set incorrectly")
assert.Equal(t, 8*time.Minute, cfg.ContainerStartTimeout, "Default docker start container timeout set incorrectly")
assert.Equal(t, 4*time.Minute, cfg.ContainerCreateTimeout, "Default docker create container timeout set incorrectly")
assert.False(t, cfg.PrivilegedDisabled.Enabled(), "Default PrivilegedDisabled set incorrectly")
assert.Equal(t, []dockerclient.LoggingDriver{dockerclient.JSONFileDriver, dockerclient.NoneDriver, dockerclient.AWSLogsDriver},
cfg.AvailableLoggingDrivers, "Default logging drivers set incorrectly")
Expand Down
13 changes: 13 additions & 0 deletions agent/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ func parseContainerStartTimeout() time.Duration {
return containerStartTimeout
}

func parseContainerCreateTimeout() time.Duration {
var containerCreateTimeout time.Duration
parsedCreateTimeout := parseEnvVariableDuration("ECS_CONTAINER_CREATE_TIMEOUT")
if parsedCreateTimeout >= minimumContainerCreateTimeout {
containerCreateTimeout = parsedCreateTimeout
// do the parsedCreateTimeout != 0 check for the same reason as in getDockerStopTimeout()
} else if parsedCreateTimeout != 0 {
containerCreateTimeout = minimumContainerCreateTimeout
shubham2892 marked this conversation as resolved.
Show resolved Hide resolved
seelog.Warnf("Discarded invalid value for container create timeout, parsed as: %v", parsedCreateTimeout)
}
return containerCreateTimeout
}

func parseImagePullInactivityTimeout() time.Duration {
var imagePullInactivityTimeout time.Duration
parsedImagePullInactivityTimeout := parseEnvVariableDuration("ECS_IMAGE_PULL_INACTIVITY_TIMEOUT")
Expand Down
3 changes: 3 additions & 0 deletions agent/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ type Config struct {
// ContainerStartTimeout specifies the amount of time to wait to start a container
ContainerStartTimeout time.Duration

// ContainerCreateTimeout specifies the amount of time to wait to create a container
ContainerCreateTimeout time.Duration

// DependentContainersPullUpfront specifies whether pulling images upfront should be applied to this agent.
// Default false
DependentContainersPullUpfront BooleanDefaultFalse
Expand Down
2 changes: 1 addition & 1 deletion agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestCreateContainer(t *testing.T) {
)
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
metadata := client.CreateContainer(ctx, nil, hostConfig, name, dockerclient.CreateContainerTimeout)
metadata := client.CreateContainer(ctx, nil, hostConfig, name, defaultTestConfig().ContainerCreateTimeout)
assert.NoError(t, metadata.Error)
assert.Equal(t, "id", metadata.DockerID)
assert.Nil(t, metadata.ExitCode, "Expected a created container to not have an exit code")
Expand Down
3 changes: 0 additions & 3 deletions agent/dockerclient/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ const (
LoadImageTimeout = 2 * time.Minute
// RemoveImageTimeout is the timeout for the RemoveImage API.
RemoveImageTimeout = 3 * time.Minute

// CreateContainerTimeout is the timeout for the CreateContainer API.
CreateContainerTimeout = 4 * time.Minute
// ListContainersTimeout is the timeout for the ListContainers API.
ListContainersTimeout = 10 * time.Minute
// InspectContainerTimeout is the timeout for the InspectContainer API.
Expand Down
2 changes: 1 addition & 1 deletion agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ func (engine *DockerTaskEngine) createContainer(task *apitask.Task, container *a

createContainerBegin := time.Now()
metadata := client.CreateContainer(engine.ctx, config, hostConfig,
dockerContainerName, dockerclient.CreateContainerTimeout)
dockerContainerName, engine.cfg.ContainerCreateTimeout)
if metadata.DockerID != "" {
seelog.Infof("Task engine [%s]: created docker container for task: %s -> %s",
task.Arn, container.Name, metadata.DockerID)
Expand Down