Skip to content

Commit a2b197d

Browse files
committed
Use AWS SDK logic to detect retryable errors
Uses the AWS SDK logic to detect API operations that fail due to retryable errors, like throttling or network issues.
1 parent 4a3076f commit a2b197d

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

  • cmd/cloud-controller-manager-aws-tests-ext/e2e

cmd/cloud-controller-manager-aws-tests-ext/e2e/helper.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/aws/aws-sdk-go-v2/aws"
10+
"github.com/aws/aws-sdk-go-v2/aws/retry"
1011
"github.com/aws/aws-sdk-go-v2/config"
1112
ec2 "github.com/aws/aws-sdk-go-v2/service/ec2"
1213
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
@@ -199,16 +200,13 @@ func ec2IsNotFoundError(err error) bool {
199200
strings.Contains(errMsg, "InvalidGroup.Malformed")
200201
}
201202

202-
// isAWSThrottlingError checks if an error is an AWS throttling/rate limit error.
203-
func isAWSThrottlingError(err error) bool {
203+
// isAWSRetryableError checks if an error is retryable using AWS SDK's standard retry logic.
204+
func isAWSRetryableError(err error) bool {
204205
if err == nil {
205206
return false
206207
}
207-
errMsg := err.Error()
208-
return strings.Contains(errMsg, "Throttling") ||
209-
strings.Contains(errMsg, "RequestLimitExceeded") ||
210-
strings.Contains(errMsg, "TooManyRequests") ||
211-
strings.Contains(errMsg, "RequestThrottled")
208+
result := retry.IsErrorRetryables(retry.DefaultRetryables).IsErrorRetryable(err)
209+
return result == aws.TrueTernary
212210
}
213211

214212
// createAWSSecurityGroup creates a test security group.
@@ -330,8 +328,8 @@ func waitForSecurityGroupDeletion(ctx context.Context, ec2Client *ec2.Client, sg
330328
// First check if SG still exists
331329
exists, err := securityGroupExists(pollCtx, ec2Client, sgID)
332330
if err != nil {
333-
// Handle throttling errors by continuing to poll
334-
if isAWSThrottlingError(err) {
331+
// Handle retryable errors by continuing to poll
332+
if isAWSRetryableError(err) {
335333
framework.Logf("AWS throttling encountered while checking security group %s, retrying...", sgID)
336334
return false, nil
337335
}
@@ -346,8 +344,8 @@ func waitForSecurityGroupDeletion(ctx context.Context, ec2Client *ec2.Client, sg
346344
// Try to delete it
347345
err = deleteAWSSecurityGroup(pollCtx, ec2Client, sgID)
348346
if err != nil {
349-
// Handle throttling errors by continuing to poll
350-
if isAWSThrottlingError(err) {
347+
// Handle retryable errors by continuing to poll
348+
if isAWSRetryableError(err) {
351349
framework.Logf("AWS throttling encountered while deleting security group %s, retrying...", sgID)
352350
return false, nil
353351
}

0 commit comments

Comments
 (0)