From aeca99750581b5cb88820e923bcc39ac852e0426 Mon Sep 17 00:00:00 2001 From: York Chen Date: Wed, 20 Apr 2022 19:31:17 -0400 Subject: [PATCH] feat: flags to configure exponential backoff retry --- controllers/kustomization_controller.go | 7 ++++++- main.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/controllers/kustomization_controller.go b/controllers/kustomization_controller.go index 1a5f0210..47a0d914 100644 --- a/controllers/kustomization_controller.go +++ b/controllers/kustomization_controller.go @@ -50,6 +50,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/predicate" + "sigs.k8s.io/controller-runtime/pkg/ratelimiter" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" @@ -96,6 +97,7 @@ type KustomizationReconcilerOptions struct { MaxConcurrentReconciles int HTTPRetry int DependencyRequeueInterval time.Duration + RateLimiter ratelimiter.RateLimiter } func (r *KustomizationReconciler) SetupWithManager(mgr ctrl.Manager, opts KustomizationReconcilerOptions) error { @@ -142,7 +144,10 @@ func (r *KustomizationReconciler) SetupWithManager(mgr ctrl.Manager, opts Kustom handler.EnqueueRequestsFromMapFunc(r.requestsForRevisionChangeOf(bucketIndexKey)), builder.WithPredicates(SourceRevisionChangePredicate{}), ). - WithOptions(controller.Options{MaxConcurrentReconciles: opts.MaxConcurrentReconciles}). + WithOptions(controller.Options{ + MaxConcurrentReconciles: opts.MaxConcurrentReconciles, + RateLimiter: opts.RateLimiter, + }). Complete(r) } diff --git a/main.go b/main.go index 9e9eff60..2b125232 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ import ( "github.com/fluxcd/pkg/runtime/acl" "github.com/fluxcd/pkg/runtime/client" + helper "github.com/fluxcd/pkg/runtime/controller" "github.com/fluxcd/pkg/runtime/events" "github.com/fluxcd/pkg/runtime/leaderelection" "github.com/fluxcd/pkg/runtime/logger" @@ -73,6 +74,7 @@ func main() { kubeConfigOpts client.KubeConfigOptions logOptions logger.Options leaderElectionOptions leaderelection.Options + rateLimiterOptions helper.RateLimiterOptions aclOptions acl.Options watchAllNamespaces bool httpRetry int @@ -93,6 +95,7 @@ func main() { leaderElectionOptions.BindFlags(flag.CommandLine) aclOptions.BindFlags(flag.CommandLine) kubeConfigOpts.BindFlags(flag.CommandLine) + rateLimiterOptions.BindFlags(flag.CommandLine) flag.Parse() ctrl.SetLogger(logger.NewLogger(logOptions)) @@ -151,6 +154,7 @@ func main() { MaxConcurrentReconciles: concurrent, DependencyRequeueInterval: requeueDependency, HTTPRetry: httpRetry, + RateLimiter: helper.GetRateLimiter(rateLimiterOptions), }); err != nil { setupLog.Error(err, "unable to create controller", "controller", controllerName) os.Exit(1)