Skip to content

Commit

Permalink
Add SDK retry and set reconcile concurrency to 10 (#114)
Browse files Browse the repository at this point in the history
Signed-off-by: Yu Jiang <[email protected]>
  • Loading branch information
carlyjiang authored Jun 15, 2023
1 parent d9bb6ab commit 288e291
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions controllers/iamrole_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}

Expand Down
17 changes: 16 additions & 1 deletion pkg/awsapi/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 288e291

Please sign in to comment.