-
Notifications
You must be signed in to change notification settings - Fork 620
Initialize IP Comaptibility config before service clients are created #4568
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
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f9caf82
to
2da7f74
Compare
amogh09
commented
Apr 10, 2025
amogh09
commented
Apr 10, 2025
amogh09
commented
Apr 10, 2025
amogh09
commented
Apr 10, 2025
mye956
reviewed
Apr 10, 2025
mye956
reviewed
Apr 10, 2025
ShelbyZ
previously approved these changes
Apr 11, 2025
d824ca9
to
f98ef82
Compare
ba04f21
to
2815ad6
Compare
mye956
reviewed
Apr 14, 2025
mye956
reviewed
Apr 14, 2025
mye956
approved these changes
Apr 14, 2025
ShelbyZ
approved these changes
Apr 14, 2025
xxx0624
pushed a commit
to xxx0624/amazon-ecs-agent
that referenced
this pull request
Apr 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently IP compatibility config variables are initialized as a part of
ecsAgent
startup in itsstart
method. This happens after some service clients such as ECS Client and ECR Client have been initialized. In future, service client configuration will depend on IP compatibility, so IP compatibility needs to be determined earlier.So, this PR moves IP Compatibility config variables from global variables to fields of
type Config struct
and initializes them when aConfig
is created byNewConfig
function. Note that IP Compatibility initialization depends on MAC resolution of primary ENI in case of EC2 Launch Type. So, config initialization now involves a call IMDS to fetch the MAC address of the primary ENI.NewConfig
is already provided anec2.EC2MetadataClient
so the same client is used to call IMDS to fetch primary ENI's mac address. Note that this call to IMDS is not a net new dependency on IMDS because Agent already does this as a part ofecsAgent.start
method. We are just doing it one more time during config initialization.Implementation details
type IPCompatibility struct
for storing IPv4 and IPv6 compatibility status.config
package and add a newInstanceIPCompatibility ipcompatibility.IPCompatibility
field toconfig.Config
struct.config
package toutils/net
package.config.NewConfig
function so that it callsconfig.determineIPCompatibility
method to determine and set IP compatibility.config.determineIPCompatibility
method on Linux is set up to fetch MAC address of the primary ENI from IMDS (for EC2 Launch Type only) and then callDetermineIPCompatibility
function fromutils/net
.app/agent.go
.config.NewConfig
function typically passec2.NewBlackholeEC2MetadataClient()
as a parameter which returns an error on every method call. This worked fine until now asNewConfig
did not error out on IMDS call failures, however, with this change that no longer holds. So, a new fake implementation of IMDS client namedFakeEC2MetadataClient
is added and the tests are updated to use this implementation instead. The implementation returns a "not implemented" error for all API calls except forPrimaryENIMAC
call that returns a non-error response.Testing
New tests cover the changes: yes
Ran Agent on three instances - dual-stack, IPv4-only, and IPv6-only - and verified in the logs that instance IP compatibility is determined correctly in all three cases.
Description for the changelog
Additional Information
Does this PR include breaking model changes? If so, Have you added transformation functions?
No
Does this PR include the addition of new environment variables in the README?
No
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.