From 288e2910847971468dac80542af2873d5969b2ed Mon Sep 17 00:00:00 2001 From: Yu Jiang Date: Wed, 14 Jun 2023 17:07:59 -0700 Subject: [PATCH] Add SDK retry and set reconcile concurrency to 10 (#114) Signed-off-by: Yu Jiang --- controllers/iamrole_controller.go | 2 ++ pkg/awsapi/iam.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/controllers/iamrole_controller.go b/controllers/iamrole_controller.go index b3aa880..4137daf 100644 --- a/controllers/iamrole_controller.go +++ b/controllers/iamrole_controller.go @@ -32,6 +32,7 @@ import ( "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" @@ -383,6 +384,7 @@ func (r *IamroleReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&iammanagerv1alpha1.Iamrole{}). WithEventFilter(StatusUpdatePredicate{}). + WithOptions(controller.Options{MaxConcurrentReconciles: 10}). Complete(r) } diff --git a/pkg/awsapi/iam.go b/pkg/awsapi/iam.go index 96c69d3..5a00202 100644 --- a/pkg/awsapi/iam.go +++ b/pkg/awsapi/iam.go @@ -7,9 +7,12 @@ import ( "context" "fmt" "strings" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/aws/client" + "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam/iamiface" @@ -70,8 +73,20 @@ type IAM struct { } func NewIAM(region string) *IAM { + config := aws.NewConfig(). + WithRegion(region). + WithCredentialsChainVerboseErrors(true) + + // Setup retryer + request.WithRetryer(config, client.DefaultRetryer{ + NumMaxRetries: 12, + MinThrottleDelay: time.Second * 5, + MaxThrottleDelay: time.Second * 60, + MinRetryDelay: time.Second * 1, + MaxRetryDelay: time.Second * 5, + }) - sess, err := session.NewSession(&aws.Config{Region: aws.String(region)}) + sess, err := session.NewSession(config) if err != nil { panic(err) }