Skip to content

Commit

Permalink
feat: allow configuring reconciliation concurrency (#628)
Browse files Browse the repository at this point in the history
* feat: allow configuring reconciliation concurrency

* fix: add maxConcurrentReconciles option in chart
  • Loading branch information
xabufr authored Mar 5, 2025
1 parent 07a1390 commit f0d78e6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions charts/ingressmonitorcontroller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions charts/ingressmonitorcontroller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
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 f0d78e6

Please sign in to comment.