Skip to content

Commit

Permalink
manager: make leader election timeouts configurable
Browse files Browse the repository at this point in the history
Adding the following options:

  -leader-election-lease-duration duration
        Duration, in seconds, that non-leader candidates will wait to
        force acquire leadership. Defaults to 15 seconds. (default 15s)
  -leader-election-renew-deadline duration
        Duration, in seconds, that the acting leader will retry
	refreshing leadership before giving up. Defaults to 10 seconds.
        (default 10s)
  -leader-election-retry-period duration
	Duration, in seconds, the LeaderElector clients should wait
        between tries of actions. Defaults to 5 seconds. (default 5s)

Some container platforms (like OpenShift) have recommendations for these
timeout that differ from the Kubernetes defaults. With these options,
deployments can define the timeouts according to their own preferences.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Jan 12, 2024
1 parent 76cee30 commit d419b84
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,25 @@ func init() {

func main() {
var (
metricsAddr string
probeAddr string
enableLeaderElection bool
showVersion bool
enableAdmissionWebhooks bool
ctx = context.Background()
cfg = util.NewConfig()
metricsAddr string
probeAddr string
enableLeaderElection bool
leaderElectionLeaseDuration time.Duration
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
showVersion bool
enableAdmissionWebhooks bool
ctx = context.Background()
cfg = util.NewConfig()
)
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.DurationVar(&leaderElectionLeaseDuration, "leader-election-lease-duration", 15*time.Second, "Duration, in seconds, that non-leader candidates will wait to force acquire leadership. Defaults to 15 seconds.")
flag.DurationVar(&leaderElectionRenewDeadline, "leader-election-renew-deadline", 10*time.Second, "Duration, in seconds, that the acting leader will retry refreshing leadership before giving up. Defaults to 10 seconds.")
flag.DurationVar(&leaderElectionRetryPeriod, "leader-election-retry-period", 5*time.Second, "Duration, in seconds, the LeaderElector clients should wait between tries of actions. Defaults to 5 seconds.")
flag.DurationVar(&cfg.ReclaimSpaceTimeout, "reclaim-space-timeout", cfg.ReclaimSpaceTimeout, "Timeout for reclaimspace operation")
flag.IntVar(&cfg.MaxConcurrentReconciles, "max-concurrent-reconciles", cfg.MaxConcurrentReconciles, "Maximum number of concurrent reconciles")
flag.StringVar(&cfg.Namespace, "namespace", cfg.Namespace, "Namespace where the CSIAddons pod is deployed")
Expand Down Expand Up @@ -122,6 +128,9 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "e8cd140a.openshift.io",
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &leaderElectionRenewDeadline,
RetryPeriod: &leaderElectionRetryPeriod,
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
Expand Down

0 comments on commit d419b84

Please sign in to comment.