-
Notifications
You must be signed in to change notification settings - Fork 748
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
Refactor EC2 Metadata (IMDS) code into new typed accessor library #1225
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.
Thanks @anguslees, great cleanup.
pkg/awsutils/imds.go
Outdated
// GetMacs returns the interface addresses attached to the instance. | ||
func (imds TypedIMDS) GetMacs(ctx context.Context) ([]string, error) { |
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: GetMACs()
? 😄
e2e tests all pass: https://github.com/aws/amazon-vpc-cni-k8s/runs/1150477131?check_suite_focus=true |
pkg/awsutils/awsutils.go
Outdated
metadataAZ = "placement/availability-zone" | ||
metadataLocalIP = "local-ipv4" | ||
metadataInstanceID = "instance-id" | ||
metadataInstanceType = "instance-type" | ||
metadataMAC = "mac" | ||
metadataSGs = "/security-group-ids/" | ||
metadataSubnetID = "/subnet-id/" | ||
metadataVPCcidrs = "/vpc-ipv4-cidr-blocks/" | ||
metadataDeviceNum = "/device-number/" | ||
metadataInterface = "/interface-id/" | ||
metadataSGs = "/security-group-ids" | ||
metadataSubnetID = "/subnet-id" | ||
metadataVPCcidrs = "/vpc-ipv4-cidr-blocks" | ||
metadataDeviceNum = "/device-number" | ||
metadataInterface = "/interface-id" | ||
metadataSubnetCIDR = "/subnet-ipv4-cidr-block" | ||
metadataIPv4s = "/local-ipv4s" |
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.
Btw, seems like these ones are only used in the tests now, maybe we should move them out?
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.
Oops, yes meant to include that patch too. Done.
Goal: Make it clearer what is cached, and not cached.
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 @anguslees :)
Refactor EC2 Metadata code into a typed wrapper. The idea is to split out the low-level mechanism (imds.go) from clever caching or other logic (awsutils.go).
Reviewer: This is intended to be a no-op "obviously safe" refactor of metadata lookup code. If there's something that looks surprising or unclear, I'm happy to simplify it further.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.