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

Awsvpc windows : Check if the pause image is loaded on the container instance #2498

Merged
merged 4 commits into from
Jul 6, 2020

Conversation

rawahars
Copy link
Contributor

Summary

This change is the first step for enabling awsvpc network mode for ECS Windows.
We will be caching pause image in the ECS-Optimized Windows AMI. When the agent starts, we will check if the pause image has been loaded. Without a pause container image loaded on the container instance, awsvpc mode cannot be supported by the instance.
The changes are specific for Windows instances.

Implementation details

Majority of the changes are refactoring of existing code which is used in Linux. We have made following changes-

Moved common functions from pause_linux.go to load.go
Moved the common code from IsLoaded function to a function in load.go
Unit tests for the same were moved from Linux specific test files to common test files

Testing

The unit tests and integration tests were executed on Linux and Windows platform.

New tests cover the changes:
No. We will be reusing the existing code and relevant unit tests which have been moved to the common files.
New tests cover the changes:

Description for the changelog

On agent startup for Windows instances, check if the pause image has been loaded.

Licensing

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

rawahars and others added 3 commits June 25, 2020 06:18
… We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded. The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files

This was a refactoring change with minimal addition of new code
agent/eni/pause/load.go Outdated Show resolved Hide resolved
agent/eni/pause/pause_windows.go Outdated Show resolved Hide resolved
agent/app/agent_windows.go Show resolved Hide resolved
Comment on lines 60 to 61
DefaultPauseContainerImageName = "amazonaws.com/ecs/pause-windows"
DefaultPauseContainerTag = "latest"
Copy link
Contributor

Choose a reason for hiding this comment

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

why not move these default values into the const block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed with @sparrc , we have added the Windows pause image name and tag in the Makefile and corresponding changes have been made in build file to invoke Windows agent build using the loader flags.

Additionally, a Powershell script has been created which can build standalone agent on Windows.

Copy link
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

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

Overall changes look good, left minor comments and questions.

agent/app/agent_windows.go Outdated Show resolved Hide resolved
@@ -279,5 +279,9 @@ func (agent *ecsAgent) getPlatformDevices() []*ecs.PlatformDevice {
}

func (agent *ecsAgent) loadPauseContainer() error {
return nil
//The pause image would be cached in th ECS-Optimized Windows AMI's and will be available. We will throw an error if the image is not loaded.
//If the agent is run on non-supported instances then pause image has to be loaded manually by the client.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by non-supported instance types and manual loading of pause container? Could you please elaborate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

non-supported instances are those which are launched using Non-ECS-Optimized Windows AMI. Manual loading of the pause container refers to creating/loading (using docker load) a pause image.

@@ -57,6 +57,8 @@ func DefaultConfig() Config {
programData := utils.DefaultIfBlank(os.Getenv("ProgramData"), `C:\ProgramData`)
ecsRoot := filepath.Join(programData, "Amazon", "ECS")
dataDir := filepath.Join(ecsRoot, "data")
DefaultPauseContainerImageName = "amazonaws.com/ecs/pause-windows"
DefaultPauseContainerTag = "latest"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does using latest make sense given that we might use different ECS Optimized Windows AMIs?
Can the pause containers tag be something specific like ltsc2019 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Considering that ECS would support future releases of Windows, it would be advisable to use a generic tag. We can probably consider checking the version of windows on the pause container to ensure that it is using the supported version.

agent/eni/pause/load.go Outdated Show resolved Hide resolved
agent/eni/pause/load.go Outdated Show resolved Hide resolved
config.DefaultPauseContainerImageName, config.DefaultPauseContainerTag, dockerClient)

if err != nil {
return false, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are some errors wrapped and others not? Can you make it consistent across the module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error message returned from 'getPauseContainerImage' is sufficient to understand the error.
Therefore, we have returned the same error from this function.

agent/eni/pause/pause_unsupported.go Show resolved Hide resolved
agent/eni/pause/pause_windows.go Show resolved Hide resolved
@@ -57,6 +57,8 @@ func DefaultConfig() Config {
programData := utils.DefaultIfBlank(os.Getenv("ProgramData"), `C:\ProgramData`)
ecsRoot := filepath.Join(programData, "Amazon", "ECS")
dataDir := filepath.Join(ecsRoot, "data")
DefaultPauseContainerImageName = "amazonaws.com/ecs/pause-windows"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be a const or a var?
Also should there be a mechanism for customers to override the defaultPauseContainer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed with the agent team, we have added the Windows pause image name and tag in the Makefile and corresponding changes have been made in build file to invoke Windows agent build using the loader flags. The default values for both name and tag will be injected using the loader flag.

Additionally, a Powershell script has been created which can build standalone agent on Windows.

Copy link
Contributor

@yhlee-aws yhlee-aws left a comment

Choose a reason for hiding this comment

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

Can you squash some of the commits into one? merges you'll have to leave as is, but at least the last 3 commits could be squashed into one commit.

@rawahars rawahars force-pushed the awsvpc-windows branch 2 times, most recently from d6d2264 to 3616559 Compare July 1, 2020 02:32
@rawahars rawahars requested review from vsiddharth and yhlee-aws July 1, 2020 02:34
Copy link
Contributor

@sparrc sparrc left a comment

Choose a reason for hiding this comment

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

I'm curious why did you decide to add env vars for the windows pause container?

Currently we set the linux pause container name using build flags in the Makefile target (see https://github.com/aws/amazon-ecs-agent/blob/master/Makefile#L148)

Why was this pattern not followed? If there is some reason that windows cannot follow this pattern, perhaps we should make it consistent and set the linux pause container name and tag using env vars as well.


// We check if the pause container image name and tag are overridden by setting an environment variable
// If not then we assign the default name and tag
pauseContainerImageNameFromEnv := os.Getenv("PAUSE_CONTAINER_IMAGE_NAME")
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with our other env vars, these should be prepended with "ECS_"

Copy link
Contributor

Choose a reason for hiding this comment

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

also, these should be parsed in the environmentConfig function, where we parse the rest of our env vars: https://github.com/aws/amazon-ecs-agent/blob/master/agent/config/config.go#L484

Copy link
Contributor Author

@rawahars rawahars Jul 1, 2020

Choose a reason for hiding this comment

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

Following our offline discussion, we have decided against introducing any environment variables.
As discussed, we have added the Windows pause image name and tag in the Makefile and corresponding changes have been made in build file to invoke Windows agent build using the loader flags.

Additionally, a Powershell script has been created which can build standalone agent on Windows.

@rawahars rawahars force-pushed the awsvpc-windows branch 2 times, most recently from 96e69fa to fe2291e Compare July 1, 2020 23:05
@rawahars rawahars requested a review from sparrc July 1, 2020 23:17
scripts/build Outdated Show resolved Hide resolved
1. The pause container image name and tag have been moved to Makefile
2. The corresponding config is populated using loader flags at build time.
This is similar to how Linux agent populates these values
3. Formatting changes
4. Modified the Readme
Copy link
Contributor

@sparrc sparrc left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@fenxiong fenxiong merged commit d12ec98 into aws:awsvpc-windows Jul 6, 2020
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Mar 4, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files

This was a refactoring change with minimal addition of new code
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Mar 4, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files

This was a refactoring change with minimal addition of new code
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Mar 4, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Apr 22, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files
@rawahars rawahars deleted the awsvpc-windows branch April 28, 2021 04:02
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Jun 23, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Jun 24, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Jun 29, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files
rawahars added a commit to rawahars/amazon-ecs-agent that referenced this pull request Jun 29, 2021
…instance (aws#2498)

* Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded.  The following changes are made as part of this commit:

1. Moved common functions from pause_linux.go to load.go
2. Moved the common code from IsLoaded function to a function in load.go
3. Unit tests for the same were moved from Linux specific files to common files
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.

6 participants