From 80c9d8dc024afaec09564158c6900faff1b9f72e Mon Sep 17 00:00:00 2001 From: Vela WU <50354807+wwvela@users.noreply.github.com> Date: Thu, 18 Jul 2024 21:32:57 -0700 Subject: [PATCH] add retry to avoid ECR get auth token failed for some transient issues (#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 --- nodeadm/internal/aws/ecr/ecr.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nodeadm/internal/aws/ecr/ecr.go b/nodeadm/internal/aws/ecr/ecr.go index 74fcef3fe..2b113e28a 100644 --- a/nodeadm/internal/aws/ecr/ecr.go +++ b/nodeadm/internal/aws/ecr/ecr.go @@ -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" @@ -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 }