diff --git a/controllers/kamajicontrolplane_controller.go b/controllers/kamajicontrolplane_controller.go index 58d5ee3..1d0ed1f 100644 --- a/controllers/kamajicontrolplane_controller.go +++ b/controllers/kamajicontrolplane_controller.go @@ -19,6 +19,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" ctrllog "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" @@ -27,6 +28,8 @@ import ( // KamajiControlPlaneReconciler reconciles a KamajiControlPlane object. type KamajiControlPlaneReconciler struct { + MaxConcurrentReconciles int + client client.Client } @@ -281,5 +284,6 @@ func (r *KamajiControlPlaneReconciler) SetupWithManager(mgr ctrl.Manager) error }))). Owns(&kamajiv1alpha1.TenantControlPlane{}). Owns(&corev1.Secret{}). + WithOptions(controller.Options{MaxConcurrentReconciles: r.MaxConcurrentReconciles}). Complete(r) } diff --git a/main.go b/main.go index d44e04a..44098da 100644 --- a/main.go +++ b/main.go @@ -37,13 +37,14 @@ func init() { } func main() { - metricsAddr, enableLeaderElection, probeAddr := "", false, "" + metricsAddr, enableLeaderElection, probeAddr, maxConcurrentReconciles := "", false, "", 1 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 KamajiControlPlane reconciles which can be run") opts := zap.Options{ Development: true, @@ -70,7 +71,7 @@ func main() { os.Exit(1) } - if err = (&controllers.KamajiControlPlaneReconciler{}).SetupWithManager(mgr); err != nil { + if err = (&controllers.KamajiControlPlaneReconciler{MaxConcurrentReconciles: maxConcurrentReconciles}).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KamajiControlPlane") os.Exit(1) }