Skip to content

Commit

Permalink
feat: max concurrent reconciles flag
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion committed May 17, 2024
1 parent f29662f commit 8409977
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions controllers/kamajicontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -27,6 +28,8 @@ import (

// KamajiControlPlaneReconciler reconciles a KamajiControlPlane object.
type KamajiControlPlaneReconciler struct {
MaxConcurrentReconciles int

client client.Client
}

Expand Down Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit 8409977

Please sign in to comment.