Skip to content

Commit

Permalink
add retry to avoid ECR get auth token failed for some transient issues (
Browse files Browse the repository at this point in the history
awslabs#1886)

* add retry to avoid fetching token failed with some transient issues

* add retry to avoid ECR get auth token failed for some transient issues

* add retry to avoid ECR get auth token failed for some transient issues
  • Loading branch information
wwvela authored and mebays committed Jul 26, 2024
1 parent 214a5d4 commit 80c9d8d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nodeadm/internal/aws/ecr/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"fmt"
"net"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/aws/imds"
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/system"
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/util"
)

// Returns the base64 encoded authorization token string for ECR of the format "AWS:XXXXX"
Expand All @@ -19,7 +21,11 @@ func GetAuthorizationToken(awsRegion string) (string, error) {
return "", err
}
ecrClient := ecr.NewFromConfig(awsConfig)
token, err := ecrClient.GetAuthorizationToken(context.Background(), &ecr.GetAuthorizationTokenInput{})
var token *ecr.GetAuthorizationTokenOutput
err = util.RetryExponentialBackoff(3, 2*time.Second, func() error {
token, err = ecrClient.GetAuthorizationToken(context.Background(), &ecr.GetAuthorizationTokenInput{})
return err
})
if err != nil {
return "", err
}
Expand Down

0 comments on commit 80c9d8d

Please sign in to comment.