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

Refactor EC2 Metadata (IMDS) code into new typed accessor library #1225

Merged
merged 1 commit into from
Sep 23, 2020

Conversation

anguslees
Copy link
Contributor

@anguslees anguslees commented Sep 22, 2020

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.

Copy link
Contributor

@mogren mogren left a 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/awsutils.go Show resolved Hide resolved
Comment on lines 59 to 60
// GetMacs returns the interface addresses attached to the instance.
func (imds TypedIMDS) GetMacs(ctx context.Context) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: GetMACs()? 😄

pkg/awsutils/imds.go Show resolved Hide resolved
pkg/awsutils/awsutils.go Show resolved Hide resolved
@mogren
Copy link
Contributor

mogren commented Sep 22, 2020

Comment on lines 45 to 56
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"
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@mogren mogren merged commit 4abab82 into aws:master Sep 23, 2020
@anguslees anguslees deleted the typed-md branch September 23, 2020 01:46
Copy link
Contributor

@jayanthvn jayanthvn left a comment

Choose a reason for hiding this comment

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

Thanks @anguslees :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants