diff --git a/README.md b/README.md index 2b36e4c4..ce39982f 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,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. + * `--http-endpoint`: The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: `:8080` which corresponds to port 8080 on local host). The default is empty string, which means the server is disabled. * `--metrics-address`: (deprecated) The TCP network address where the prometheus metrics endpoint will run (example: `:8080` which corresponds to port 8080 on local host). The default is empty string, which means metrics endpoint is disabled. diff --git a/cmd/snapshot-controller/main.go b/cmd/snapshot-controller/main.go index 4f516117..ff78b9ee 100644 --- a/cmd/snapshot-controller/main.go +++ b/cmd/snapshot-controller/main.go @@ -20,7 +20,6 @@ import ( "context" "flag" "fmt" - "k8s.io/client-go/util/workqueue" "os" "os/signal" "sync" @@ -30,6 +29,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + "k8s.io/client-go/util/workqueue" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -53,8 +53,11 @@ var ( showVersion = flag.Bool("version", false, "Show version.") threads = flag.Int("worker-threads", 10, "Number of worker threads.") - 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.") httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics, will listen (example: :8080). The default is empty string, which means the server is disabled.") metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.") @@ -210,6 +213,9 @@ 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) }