Skip to content

Commit

Permalink
feat: allow configuring reconciliation concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
xabufr committed Feb 18, 2025
1 parent 07a1390 commit fb6b836
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/controllers/endpointmonitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit fb6b836

Please sign in to comment.