From fb6b8360e9ab473f214443b1d34d9bc56e2466cd Mon Sep 17 00:00:00 2001 From: Thomas Loubiou Date: Tue, 18 Feb 2025 10:25:02 +0100 Subject: [PATCH 1/2] feat: allow configuring reconciliation concurrency --- main.go | 6 +++++- pkg/controllers/endpointmonitor_controller.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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) } From 9cba64016ba67779d6afc2fa9500b54c22a092f6 Mon Sep 17 00:00:00 2001 From: Thomas Loubiou Date: Tue, 18 Feb 2025 11:24:39 +0100 Subject: [PATCH 2/2] fix: add maxConcurrentReconciles option in chart --- charts/ingressmonitorcontroller/templates/deployment.yaml | 1 + charts/ingressmonitorcontroller/values.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/charts/ingressmonitorcontroller/templates/deployment.yaml b/charts/ingressmonitorcontroller/templates/deployment.yaml index 9883f687..0c908669 100644 --- a/charts/ingressmonitorcontroller/templates/deployment.yaml +++ b/charts/ingressmonitorcontroller/templates/deployment.yaml @@ -52,6 +52,7 @@ spec: - --health-probe-bind-address=:8081 - --metrics-bind-address=127.0.0.1:8080 - --leader-elect + - --max-concurrent-reconciles={{ .Values.maxConcurrentReconciles }} command: - /manager env: diff --git a/charts/ingressmonitorcontroller/values.yaml b/charts/ingressmonitorcontroller/values.yaml index 6d2a52d8..a0e91956 100644 --- a/charts/ingressmonitorcontroller/values.yaml +++ b/charts/ingressmonitorcontroller/values.yaml @@ -41,6 +41,9 @@ namespaceOverride: "" # Leave empty for full access or specify a comma separated list of namespaces to watch watchNamespaces: "" +# Number of concurrent reconciles +maxConcurrentReconciles: 1 + # Name of secret containing configSecretName: "imc-config"