diff --git a/main.go b/main.go index 704d1a97..19f78e9b 100644 --- a/main.go +++ b/main.go @@ -59,11 +59,15 @@ func main() { var metricsAddr string var enableLeaderElection bool var probeAddr string + var maxConcurrentReconciles int flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") flag.BoolVar(&enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") + flag.IntVar(&maxConcurrentReconciles, "max-concurrent-reconciles", 1, + "The maximum number of concurrent Reconciles which can be run.", + ) opts := zap.Options{ Development: false, } @@ -111,7 +115,7 @@ func main() { Log: ctrl.Log.WithName("controllers").WithName("EndpointMonitor"), Scheme: mgr.GetScheme(), MonitorServices: monitors.SetupMonitorServicesForProviders(config.Providers), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, maxConcurrentReconciles); err != nil { setupLog.Error(err, "unable to create controller", "controller", "EndpointMonitor") os.Exit(1) } diff --git a/pkg/controllers/endpointmonitor_controller.go b/pkg/controllers/endpointmonitor_controller.go index b81f5838..8684b5d4 100644 --- a/pkg/controllers/endpointmonitor_controller.go +++ b/pkg/controllers/endpointmonitor_controller.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -105,8 +106,11 @@ func (r *EndpointMonitorReconciler) Reconcile(ctx context.Context, req ctrl.Requ } // SetupWithManager sets up the controller with the Manager. -func (r *EndpointMonitorReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *EndpointMonitorReconciler) SetupWithManager(mgr ctrl.Manager, maxConcurrentReconciles int) error { return ctrl.NewControllerManagedBy(mgr). + WithOptions(controller.Options{ + MaxConcurrentReconciles: maxConcurrentReconciles, + }). For(&endpointmonitorv1alpha1.EndpointMonitor{}). Complete(r) }