diff --git a/controllers/imageupdateautomation_controller.go b/controllers/imageupdateautomation_controller.go index b1f70e37..614b2091 100644 --- a/controllers/imageupdateautomation_controller.go +++ b/controllers/imageupdateautomation_controller.go @@ -47,6 +47,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -99,6 +100,10 @@ type ImageUpdateAutomationReconciler struct { MetricsRecorder *metrics.Recorder } +type ImageUpdateAutomationReconcilerOptions struct { + MaxConcurrentReconciles int +} + // +kubebuilder:rbac:groups=image.toolkit.fluxcd.io,resources=imageupdateautomations,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=image.toolkit.fluxcd.io,resources=imageupdateautomations/status,verbs=get;update;patch // +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=gitrepositories,verbs=get;list;watch @@ -356,7 +361,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr return ctrl.Result{RequeueAfter: interval}, nil } -func (r *ImageUpdateAutomationReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *ImageUpdateAutomationReconciler) SetupWithManager(mgr ctrl.Manager, opts ImageUpdateAutomationReconcilerOptions) error { ctx := context.Background() // Index the git repository object that each I-U-A refers to if err := mgr.GetFieldIndexer().IndexField(ctx, &imagev1.ImageUpdateAutomation{}, repoRefKey, func(obj client.Object) []string { @@ -372,6 +377,9 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(mgr ctrl.Manager) err predicate.Or(predicate.GenerationChangedPredicate{}, predicates.ReconcileRequestedPredicate{}))). Watches(&source.Kind{Type: &sourcev1.GitRepository{}}, handler.EnqueueRequestsFromMapFunc(r.automationsForGitRepo)). Watches(&source.Kind{Type: &imagev1_reflect.ImagePolicy{}}, handler.EnqueueRequestsFromMapFunc(r.automationsForImagePolicy)). + WithOptions(controller.Options{ + MaxConcurrentReconciles: opts.MaxConcurrentReconciles, + }). Complete(r) } diff --git a/controllers/suite_test.go b/controllers/suite_test.go index e5baea3e..a4a93b5e 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -87,7 +87,7 @@ var _ = BeforeSuite(func(done Done) { Client: k8sManager.GetClient(), Scheme: scheme.Scheme, } - Expect(imageAutoReconciler.SetupWithManager(k8sManager)).To(Succeed()) + Expect(imageAutoReconciler.SetupWithManager(k8sManager, ImageUpdateAutomationReconcilerOptions{})).To(Succeed()) go func() { defer GinkgoRecover() diff --git a/main.go b/main.go index f47b04f8..377c73f6 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,7 @@ func main() { logOptions logger.Options leaderElectionOptions leaderelection.Options watchAllNamespaces bool + concurrent int ) flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") @@ -74,6 +75,7 @@ func main() { flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.") flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true, "Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.") + flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent resource reconciles.") clientOptions.BindFlags(flag.CommandLine) logOptions.BindFlags(flag.CommandLine) leaderElectionOptions.BindFlags(flag.CommandLine) @@ -128,7 +130,9 @@ func main() { EventRecorder: mgr.GetEventRecorderFor(controllerName), ExternalEventRecorder: eventRecorder, MetricsRecorder: metricsRecorder, - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, controllers.ImageUpdateAutomationReconcilerOptions{ + MaxConcurrentReconciles: concurrent, + }); err != nil { setupLog.Error(err, "unable to create controller", "controller", "ImageUpdateAutomation") os.Exit(1) }