From 58d51ed74cf8f6642821a1bef68e53305cc4103d Mon Sep 17 00:00:00 2001 From: Tiffany Wang Date: Wed, 4 Dec 2024 23:20:26 -0800 Subject: [PATCH] address comments --- .../aws/amazon-ecs-agent/ecs-agent/ec2/ec2_client.go | 5 +---- .../ecs-agent/ec2/ec2_metadata_client.go | 9 +++------ ecs-agent/ec2/ec2_client.go | 5 +---- ecs-agent/ec2/ec2_metadata_client.go | 9 +++------ 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_client.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_client.go index 8d8dffb06a4..1866a85f195 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_client.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_client.go @@ -23,7 +23,6 @@ import ( "github.com/aws/amazon-ecs-agent/ecs-agent/logger" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/config" ec2sdk "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/ec2/types" @@ -65,9 +64,7 @@ func NewClientImpl(awsRegion string) (Client, error) { context.TODO(), config.WithRegion(awsRegion), config.WithCredentialsProvider(credentialsProvider), - config.WithRetryer(func() aws.Retryer { - return retry.AddWithMaxAttempts(retry.NewStandard(), clientRetriesNum) - }), + config.WithRetryMaxAttempts(clientRetriesNum), ) if err != nil { return nil, err diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_metadata_client.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_metadata_client.go index 8cc38b08cf4..472d5949f14 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_metadata_client.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/ec2/ec2_metadata_client.go @@ -22,8 +22,6 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" @@ -96,7 +94,8 @@ type ec2MetadataClientImpl struct { client HttpClient } -// NewEC2MetadataClient creates an ec2metadata client to retrieve metadata +// NewEC2MetadataClient creates an ec2metadata client to retrieve metadata. +// Pass a non-nil HttpClient to mock behavior in tests. func NewEC2MetadataClient(client HttpClient) (EC2MetadataClient, error) { if client == nil { credentialsProvider := providers.NewInstanceCredentialsCache( @@ -107,9 +106,7 @@ func NewEC2MetadataClient(client HttpClient) (EC2MetadataClient, error) { cfg, err := config.LoadDefaultConfig( context.TODO(), config.WithCredentialsProvider(credentialsProvider), - config.WithRetryer(func() aws.Retryer { - return retry.AddWithMaxAttempts(retry.NewStandard(), metadataRetries) - }), + config.WithRetryMaxAttempts(metadataRetries), ) if err != nil { return nil, err diff --git a/ecs-agent/ec2/ec2_client.go b/ecs-agent/ec2/ec2_client.go index 8d8dffb06a4..1866a85f195 100644 --- a/ecs-agent/ec2/ec2_client.go +++ b/ecs-agent/ec2/ec2_client.go @@ -23,7 +23,6 @@ import ( "github.com/aws/amazon-ecs-agent/ecs-agent/logger" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/config" ec2sdk "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/ec2/types" @@ -65,9 +64,7 @@ func NewClientImpl(awsRegion string) (Client, error) { context.TODO(), config.WithRegion(awsRegion), config.WithCredentialsProvider(credentialsProvider), - config.WithRetryer(func() aws.Retryer { - return retry.AddWithMaxAttempts(retry.NewStandard(), clientRetriesNum) - }), + config.WithRetryMaxAttempts(clientRetriesNum), ) if err != nil { return nil, err diff --git a/ecs-agent/ec2/ec2_metadata_client.go b/ecs-agent/ec2/ec2_metadata_client.go index 8cc38b08cf4..472d5949f14 100644 --- a/ecs-agent/ec2/ec2_metadata_client.go +++ b/ecs-agent/ec2/ec2_metadata_client.go @@ -22,8 +22,6 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" @@ -96,7 +94,8 @@ type ec2MetadataClientImpl struct { client HttpClient } -// NewEC2MetadataClient creates an ec2metadata client to retrieve metadata +// NewEC2MetadataClient creates an ec2metadata client to retrieve metadata. +// Pass a non-nil HttpClient to mock behavior in tests. func NewEC2MetadataClient(client HttpClient) (EC2MetadataClient, error) { if client == nil { credentialsProvider := providers.NewInstanceCredentialsCache( @@ -107,9 +106,7 @@ func NewEC2MetadataClient(client HttpClient) (EC2MetadataClient, error) { cfg, err := config.LoadDefaultConfig( context.TODO(), config.WithCredentialsProvider(credentialsProvider), - config.WithRetryer(func() aws.Retryer { - return retry.AddWithMaxAttempts(retry.NewStandard(), metadataRetries) - }), + config.WithRetryMaxAttempts(metadataRetries), ) if err != nil { return nil, err