From 6e2744e4aa3c404afd7763f02805f63db64e8eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bryan=E2=84=A2?= <61433408+brycahta@users.noreply.github.com> Date: Tue, 10 Nov 2020 06:56:48 -0600 Subject: [PATCH] reduce imds retries on error (#281) --- pkg/ec2metadata/ec2metadata.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/ec2metadata/ec2metadata.go b/pkg/ec2metadata/ec2metadata.go index 4e8184d0..77097915 100644 --- a/pkg/ec2metadata/ec2metadata.go +++ b/pkg/ec2metadata/ec2metadata.go @@ -121,7 +121,7 @@ func New(metadataURL string, tries int) *Service { metadataURL: metadataURL, tries: tries, httpClient: http.Client{ - Timeout: 5 * time.Second, + Timeout: 2 * time.Second, Transport: &http.Transport{ MaxIdleConns: 10, IdleConnTimeout: 30 * time.Second, @@ -320,8 +320,12 @@ func retry(attempts int, sleep time.Duration, httpReq func() (*http.Response, er // GetNodeMetadata attempts to gather additional ec2 instance information from the metadata service func (e *Service) GetNodeMetadata() NodeMetadata { var metadata NodeMetadata - identityDoc, _ := e.GetMetadataInfo(IdentityDocPath) - err := json.NewDecoder(strings.NewReader(identityDoc)).Decode(&metadata) + identityDoc, err := e.GetMetadataInfo(IdentityDocPath) + if err != nil { + log.Log().Err(err).Msg("Unable to fetch metadata from IMDS") + return metadata + } + err = json.NewDecoder(strings.NewReader(identityDoc)).Decode(&metadata) if err != nil { log.Log().Msg("Unable to fetch instance identity document from ec2 metadata") metadata.InstanceID, _ = e.GetMetadataInfo(InstanceIDPath)