Skip to content

Commit 6e2744e

Browse files
authored
reduce imds retries on error (#281)
1 parent feb2a7f commit 6e2744e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/ec2metadata/ec2metadata.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func New(metadataURL string, tries int) *Service {
121121
metadataURL: metadataURL,
122122
tries: tries,
123123
httpClient: http.Client{
124-
Timeout: 5 * time.Second,
124+
Timeout: 2 * time.Second,
125125
Transport: &http.Transport{
126126
MaxIdleConns: 10,
127127
IdleConnTimeout: 30 * time.Second,
@@ -320,8 +320,12 @@ func retry(attempts int, sleep time.Duration, httpReq func() (*http.Response, er
320320
// GetNodeMetadata attempts to gather additional ec2 instance information from the metadata service
321321
func (e *Service) GetNodeMetadata() NodeMetadata {
322322
var metadata NodeMetadata
323-
identityDoc, _ := e.GetMetadataInfo(IdentityDocPath)
324-
err := json.NewDecoder(strings.NewReader(identityDoc)).Decode(&metadata)
323+
identityDoc, err := e.GetMetadataInfo(IdentityDocPath)
324+
if err != nil {
325+
log.Log().Err(err).Msg("Unable to fetch metadata from IMDS")
326+
return metadata
327+
}
328+
err = json.NewDecoder(strings.NewReader(identityDoc)).Decode(&metadata)
325329
if err != nil {
326330
log.Log().Msg("Unable to fetch instance identity document from ec2 metadata")
327331
metadata.InstanceID, _ = e.GetMetadataInfo(InstanceIDPath)

0 commit comments

Comments
 (0)