-
Notifications
You must be signed in to change notification settings - Fork 613
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
Passing Host IPv4 address to container metadata file #1730
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, minor comment about len checks for ec2 api call
agent/ec2/ec2_client.go
Outdated
seelog.Criticalf("Error calling DescribeInstances API: %v", err) | ||
return "", err | ||
} | ||
if len(describeInstancesOutput.Reservations) == 0 || len(describeInstancesOutput.Reservations[0].Instances) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only 1 address is expected.
, if only 1 is expected. should we explicitly check for 1 for each? am i missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we only ever pass in a single instance ID, I can't imagine a scenario in which we get more than 1 instance back. This check is to ensure we don't run into a nil pointer exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my concern!
I think it would be a good idea to write a functional test for this as well.
agent/app/agent.go
Outdated
// Get instance ID from ec2 metadata client. | ||
hostPublicIPv4Address, err := agent.ec2MetadataClient.PublicIPv4Address() | ||
if err != nil { | ||
seelog.Criticalf("Unable to retrieve Host Instance PublicIPv4 Address: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend having this as Error, not Critical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code lgtm. do we need to add the field to state file/bump version?
@sharanyad We aren't saving the Host IP to the state file, just metadata manager. I don't believe we need to bump it. |
11297d0
to
4c4a1aa
Compare
"name": "container-metadata-file-validator", | ||
"memory": 512, | ||
"cpu": 1024, | ||
"healthCheck": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need health check for this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other tests that run a custom image use the healthCheck (like v3-task-endpoint-validator). Since this test runs for ~15 seconds, doesn't hurt to have a healthCheck every 5 secs.
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
FROM microsoft/windowsservercore:latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use microsoft/nanoserver for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Decreases the image size from 11gb to 1.1gb!
|
||
agent := RunAgent(t, agentOptions) | ||
defer agent.Cleanup() | ||
agent.RequireVersion(">=1.15.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this test also checks for HostIPv4 field, shouldn't the agent version required be the most recent one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I think we should move away from requiring a version and represent these "requirements" as capabilities. For functional tests, all tests should run against the most up to date version of Agent.
@@ -0,0 +1,225 @@ | |||
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this file is essentially the same as misc/container-metadata-file-validator-windows/container-metadata-file-validator-windows.go
. is it possible to reuse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is different validation for network on linux, which is more detailed. The 2 files approach is taken from the v3-task-metadata-validator. The files are built/managed differently. In addition, the task definitions themselves are a bit different (with windows including "windows" identifiers)
99c532f
to
b5eca96
Compare
agent/app/agent_test.go
Outdated
ec2MetadataClient.EXPECT().PublicIPv4Address().Return(hostPublicIPv4Address, nil) | ||
|
||
hostPublicIPv4AddressOutput := agent.getHostPublicIPv4AddressFromEC2Metadata() | ||
assert.Equal(t, hostPublicIPv4Address, hostPublicIPv4AddressOutput) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
this can just be
assert.Equal(t, hostPublicIPv4Address, agent.getHostPublicIPv4AddressFromEC2Metadata())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, along with the test below.
}, | ||
} | ||
|
||
agent := RunAgent(t, agentOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would still require the right agent version here, since functional tests can be run for different agent images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Fixed it to remain consistent with other tests.
b5eca96
to
bba72e6
Compare
bba72e6
to
0f916d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Related issue: aws#1575 Related PR: aws#1730 PR 1730 adds the Public IP Address of the host to the container metadata file, however the EC2 host may be configured without a public address. In this case, the EC2 metadata API returns a 404 response, and the host IP is not available to containers. Example ECS Agent Log ``` [ERROR] Unable to retrieve Host Instance PublicIPv4 Address: EC2MetadataError: failed to make EC2Metadata request caused by: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body> </html> ``` This commit adds an extra field to the container metadata json, `HostPrivateIPv4Address` which is available on EC2 hosts without a public address.
Related issue: aws#1575 Related PR: aws#1730 PR 1730 adds the Public IP Address of the host to the container metadata file, however the EC2 host may be configured without a public address. In this case, the EC2 metadata API returns a 404 response, and the host IP is not available to containers. Example ECS Agent Log ``` [ERROR] Unable to retrieve Host Instance PublicIPv4 Address: EC2MetadataError: failed to make EC2Metadata request caused by: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body> </html> ``` This commit adds an extra field to the container metadata json, `HostPrivateIPv4Address` which is available on EC2 hosts without a public address.
Related issue: aws#1575 Related PR: aws#1730 PR 1730 adds the Public IP Address of the host to the container metadata file, however the EC2 host may be configured without a public address. In this case, the EC2 metadata API returns a 404 response, and the host IP is not available to containers. Example ECS Agent Log ``` [ERROR] Unable to retrieve Host Instance PublicIPv4 Address: EC2MetadataError: failed to make EC2Metadata request caused by: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body> </html> ``` This commit adds an extra field to the container metadata json, `HostPrivateIPv4Address` which is available on EC2 hosts without a public address.
Related issue: aws#1575 Related PR: aws#1730 PR 1730 adds the Public IP Address of the host to the container metadata file, however the EC2 host may be configured without a public address. In this case, the EC2 metadata API returns a 404 response, and the host IP is not available to containers. Example ECS Agent Log ``` [ERROR] Unable to retrieve Host Instance PublicIPv4 Address: EC2MetadataError: failed to make EC2Metadata request caused by: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body> </html> ``` This commit adds an extra field to the container metadata json, `HostPrivateIPv4Address` which is available on EC2 hosts without a public address.
Related issue: aws#1575 Related PR: aws#1730 PR 1730 adds the Public IP Address of the host to the container metadata file, however the EC2 host may be configured without a public address. In this case, the EC2 metadata API returns a 404 response, and the host IP is not available to containers. Example ECS Agent Log ``` [ERROR] Unable to retrieve Host Instance PublicIPv4 Address: EC2MetadataError: failed to make EC2Metadata request caused by: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body> </html> ``` This commit adds an extra field to the container metadata json, `HostPrivateIPv4Address` which is available on EC2 hosts without a public address.
Related issue: #1575 Related PR: #1730 PR 1730 adds the Public IP Address of the host to the container metadata file, however the EC2 host may be configured without a public address. In this case, the EC2 metadata API returns a 404 response, and the host IP is not available to containers. Example ECS Agent Log ``` [ERROR] Unable to retrieve Host Instance PublicIPv4 Address: EC2MetadataError: failed to make EC2Metadata request caused by: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body> </html> ``` This commit adds an extra field to the container metadata json, `HostPrivateIPv4Address` which is available on EC2 hosts without a public address.
Summary
Adds Host EC2 instance Public IPv4 address to container metadata file.
Customer ask: GitHub issue
Implementation details
Added EC2 api call to describe instance and retrieve public ipv4 address at Agent startup
Testing
Added unit tests for adding IP address to file. Manually tested as well.
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes:
Description for the changelog
Saving Host IPv4 address in container metadata file
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.