From 42aaf61852c99bda7ddd14f3f5083399df8a8748 Mon Sep 17 00:00:00 2001 From: Alex Marston Date: Thu, 14 Apr 2022 16:38:24 +0100 Subject: [PATCH] Add flags for exponential back-off retry Signed-off-by: Alex Marston --- controllers/helmrelease_controller.go | 7 ++++++- main.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/controllers/helmrelease_controller.go b/controllers/helmrelease_controller.go index c6804dcaa..250793b7f 100644 --- a/controllers/helmrelease_controller.go +++ b/controllers/helmrelease_controller.go @@ -45,6 +45,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" @@ -118,7 +119,10 @@ func (r *HelmReleaseReconciler) SetupWithManager(mgr ctrl.Manager, opts HelmRele handler.EnqueueRequestsFromMapFunc(r.requestsForHelmChartChange), builder.WithPredicates(SourceRevisionChangePredicate{}), ). - WithOptions(controller.Options{MaxConcurrentReconciles: opts.MaxConcurrentReconciles}). + WithOptions(controller.Options{ + MaxConcurrentReconciles: opts.MaxConcurrentReconciles, + RateLimiter: opts.RateLimiter, + }). Complete(r) } @@ -283,6 +287,7 @@ type HelmReleaseReconcilerOptions struct { MaxConcurrentReconciles int HTTPRetry int DependencyRequeueInterval time.Duration + RateLimiter ratelimiter.RateLimiter } func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, diff --git a/main.go b/main.go index 55ccd4a0e..8e870406a 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,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" @@ -74,6 +75,7 @@ func main() { logOptions logger.Options aclOptions acl.Options leaderElectionOptions leaderelection.Options + rateLimiterOptions helper.RateLimiterOptions defaultServiceAccount string ) @@ -90,6 +92,7 @@ func main() { logOptions.BindFlags(flag.CommandLine) aclOptions.BindFlags(flag.CommandLine) leaderElectionOptions.BindFlags(flag.CommandLine) + rateLimiterOptions.BindFlags(flag.CommandLine) kubeConfigOpts.BindFlags(flag.CommandLine) flag.Parse() @@ -148,6 +151,7 @@ func main() { MaxConcurrentReconciles: concurrent, DependencyRequeueInterval: requeueDependency, HTTPRetry: httpRetry, + RateLimiter: helper.GetRateLimiter(rateLimiterOptions), }); err != nil { setupLog.Error(err, "unable to create controller", "controller", v2.HelmReleaseKind) os.Exit(1)