From db972e7c5031627e5e305024c54dcd3aa86c288a Mon Sep 17 00:00:00 2001 From: shahra Date: Fri, 25 Jun 2021 11:38:58 +0530 Subject: [PATCH] Add command line arguments to configure leader election options --- README.md | 6 ++++++ cmd/csi-snapshotter/main.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 343c0046..2f66267a 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,12 @@ Read more about how to install the example webhook [here](deploy/kubernetes/webh * `--leader-election-namespace `: The namespace where the leader election resource exists. Defaults to the pod namespace if not set. +* `--leader-election-lease-duration `: Duration, in seconds, that non-leader candidates will wait to force acquire leadership. Defaults to 15 seconds. + +* `--leader-election-renew-deadline `: Duration, in seconds, that the acting leader will retry refreshing leadership before giving up. Defaults to 10 seconds. + +* `--leader-election-retry-period `: Duration, in seconds, the LeaderElector clients should wait between tries of actions. Defaults to 5 seconds. + * `--timeout `: Timeout of all calls to CSI driver. It should be set to value that accommodates majority of `CreateSnapshot`, `DeleteSnapshot`, and `ListSnapshots` calls. 1 minute is used by default. * `snapshot-name-prefix`: Prefix to apply to the name of a created snapshot. Default is `snapshot`. diff --git a/cmd/csi-snapshotter/main.go b/cmd/csi-snapshotter/main.go index 7e499c36..1249e5b4 100644 --- a/cmd/csi-snapshotter/main.go +++ b/cmd/csi-snapshotter/main.go @@ -66,8 +66,11 @@ var ( csiTimeout = flag.Duration("timeout", defaultCSITimeout, "The timeout for any RPCs to the CSI driver. Default is 1 minute.") extraCreateMetadata = flag.Bool("extra-create-metadata", false, "If set, add snapshot metadata to plugin snapshot requests as parameters.") - leaderElection = flag.Bool("leader-election", false, "Enables leader election.") - leaderElectionNamespace = flag.String("leader-election-namespace", "", "The namespace where the leader election resource exists. Defaults to the pod namespace if not set.") + leaderElection = flag.Bool("leader-election", false, "Enables leader election.") + leaderElectionNamespace = flag.String("leader-election-namespace", "", "The namespace where the leader election resource exists. Defaults to the pod namespace if not set.") + leaderElectionLeaseDuration = flag.Duration("leader-election-lease-duration", 15*time.Second, "Duration, in seconds, that non-leader candidates will wait to force acquire leadership. Defaults to 15 seconds.") + leaderElectionRenewDeadline = flag.Duration("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.") + leaderElectionRetryPeriod = flag.Duration("leader-election-retry-period", 5*time.Second, "Duration, in seconds, the LeaderElector clients should wait between tries of actions. Defaults to 5 seconds.") metricsAddress = flag.String("metrics-address", "", "(deprecated) The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.") httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: `:8080`). The default is empty string, which means the server is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.") @@ -236,6 +239,11 @@ func main() { if *leaderElectionNamespace != "" { le.WithNamespace(*leaderElectionNamespace) } + + le.WithLeaseDuration(*leaderElectionLeaseDuration) + le.WithRenewDeadline(*leaderElectionRenewDeadline) + le.WithRetryPeriod(*leaderElectionRetryPeriod) + if err := le.Run(); err != nil { klog.Fatalf("failed to initialize leader election: %v", err) }