Skip to content

[SFS-1439] Allow concurrent reconciles #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"flag"
"os"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -55,11 +56,18 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var maxConcurrentReconciles int
var qps float64
var burst 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.")
"Enabling this will ensure there is only one active controller manager. ")
flag.IntVar(&maxConcurrentReconciles, "max-concurrent-reconciles", 1, "Define how many concurrent reconciles are allowed.")
flag.Float64Var(&qps, "qps", 5, "The maximum QPS to the master from the client used by this controller.")
flag.IntVar(&burst, "burst", 10, "The maximum burst for throttle.")
Comment on lines +66 to +69
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we're using the same default values that are defined in the controller-runtime.


opts := zap.Options{
Development: true,
}
Expand All @@ -68,13 +76,15 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
cfg := ctrl.GetConfigOrDie()
cfg.QPS = float32(qps)
cfg.Burst = burst

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Metrics: server.Options{BindAddress: metricsAddr},
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "813ae16b.vtex.io",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand All @@ -86,7 +96,13 @@ func main() {
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
LeaderElection: enableLeaderElection,
LeaderElectionID: "813ae16b.vtex.io",
Controller: config.Controller{
MaxConcurrentReconciles: maxConcurrentReconciles,
},
})

if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand Down