@@ -44,12 +44,14 @@ func RetryAttempts(attempts uint) ClientOption {
4444}
4545
4646const (
47- vmUniqueIDProperty = "vmId"
48- imdsComputePath = "/metadata/instance/compute?api-version=2021-01-01&format=json"
49- metadataHeaderKey = "Metadata"
50- metadataHeaderValue = "true"
51- defaultRetryAttempts = 10
52- defaultIMDSEndpoint = "http://169.254.169.254"
47+ vmUniqueIDProperty = "vmId"
48+ imdsComputePath = "/metadata/instance/compute"
49+ imdsComputeAPIVersion = "api-version=2021-01-01"
50+ imdsFormatJSON = "format=json"
51+ metadataHeaderKey = "Metadata"
52+ metadataHeaderValue = "true"
53+ defaultRetryAttempts = 3
54+ defaultIMDSEndpoint = "http://169.254.169.254"
5355)
5456
5557var (
6062// NewClient creates a new imds client
6163func NewClient (opts ... ClientOption ) * Client {
6264 config := clientConfig {
63- endpoint : defaultIMDSEndpoint ,
65+ endpoint : defaultIMDSEndpoint ,
66+ retryAttempts : defaultRetryAttempts ,
6467 }
6568
6669 for _ , o := range opts {
@@ -104,6 +107,7 @@ func (c *Client) getInstanceComputeMetadata(ctx context.Context) (map[string]any
104107 if err != nil {
105108 return nil , errors .Wrap (err , "unable to build path to IMDS compute metadata" )
106109 }
110+ imdsComputeURL = imdsComputeURL + "?" + imdsComputeAPIVersion + "&" + imdsFormatJSON
107111
108112 req , err := http .NewRequestWithContext (ctx , http .MethodGet , imdsComputeURL , http .NoBody )
109113 if err != nil {
@@ -112,7 +116,6 @@ func (c *Client) getInstanceComputeMetadata(ctx context.Context) (map[string]any
112116
113117 // IMDS requires the "Metadata: true" header
114118 req .Header .Add (metadataHeaderKey , metadataHeaderValue )
115-
116119 resp , err := c .cli .Do (req )
117120 if err != nil {
118121 return nil , errors .Wrap (err , "error querying IMDS" )
0 commit comments