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
  • Loading branch information
wwvela committed Jul 19, 2024
1 parent 782f15b commit b82d0a7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions 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,15 +21,19 @@ func GetAuthorizationToken(awsRegion string) (string, error) {
return "", err
}
ecrClient := ecr.NewFromConfig(awsConfig)

for i := 0; i < 3; i++ {
token, err := ecrClient.GetAuthorizationToken(context.Background(), &ecr.GetAuthorizationTokenInput{})
if err == nil {
authData := token.AuthorizationData[0].AuthorizationToken
return *authData, nil
var token *ecr.GetAuthorizationTokenOutput
err = util.RetryExponentialBackoff(3, 2*time.Second, func() error {
token, err = ecrClient.GetAuthorizationToken(context.Background(), &ecr.GetAuthorizationTokenInput{})
if err != nil {
return err
}
return nil
})
if err != nil {
return "", err
}
return "", err
authData := token.AuthorizationData[0].AuthorizationToken
return *authData, nil
}

func (r *ECRRegistry) GetSandboxImage() string {
Expand Down

0 comments on commit b82d0a7

Please sign in to comment.