Skip to content

Commit

Permalink
reduce imds retries on error (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
brycahta authored Nov 10, 2020
1 parent feb2a7f commit 6e2744e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/ec2metadata/ec2metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e2744e

Please sign in to comment.