Skip to content

Commit b5b7190

Browse files
authored
Merge pull request #575 from bertinatto/leader-election-snapshot-controller
Add options to configure leader election in snapshot-controller
2 parents 7b156a0 + 22d4998 commit b5b7190

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ Read more about how to install the example webhook [here](deploy/kubernetes/webh
119119

120120
* `--leader-election-namespace <namespace>`: The namespace where the leader election resource exists. Defaults to the pod namespace if not set.
121121

122+
* `--leader-election-lease-duration <duration>`: Duration, in seconds, that non-leader candidates will wait to force acquire leadership. Defaults to 15 seconds.
123+
124+
* `--leader-election-renew-deadline <duration>`: Duration, in seconds, that the acting leader will retry refreshing leadership before giving up. Defaults to 10 seconds.
125+
126+
* `--leader-election-retry-period <duration>`: Duration, in seconds, the LeaderElector clients should wait between tries of actions. Defaults to 5 seconds.
127+
122128
* `--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.
123129

124130
* `--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.

cmd/snapshot-controller/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"flag"
2222
"fmt"
23-
"k8s.io/client-go/util/workqueue"
2423
"os"
2524
"os/signal"
2625
"sync"
@@ -30,6 +29,7 @@ import (
3029
"k8s.io/client-go/kubernetes/scheme"
3130
"k8s.io/client-go/rest"
3231
"k8s.io/client-go/tools/clientcmd"
32+
"k8s.io/client-go/util/workqueue"
3333

3434
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3535
"k8s.io/apimachinery/pkg/util/wait"
@@ -53,8 +53,11 @@ var (
5353
showVersion = flag.Bool("version", false, "Show version.")
5454
threads = flag.Int("worker-threads", 10, "Number of worker threads.")
5555

56-
leaderElection = flag.Bool("leader-election", false, "Enables leader election.")
57-
leaderElectionNamespace = flag.String("leader-election-namespace", "", "The namespace where the leader election resource exists. Defaults to the pod namespace if not set.")
56+
leaderElection = flag.Bool("leader-election", false, "Enables leader election.")
57+
leaderElectionNamespace = flag.String("leader-election-namespace", "", "The namespace where the leader election resource exists. Defaults to the pod namespace if not set.")
58+
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.")
59+
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.")
60+
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.")
5861

5962
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.")
6063
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
@@ -210,6 +213,9 @@ func main() {
210213
if *leaderElectionNamespace != "" {
211214
le.WithNamespace(*leaderElectionNamespace)
212215
}
216+
le.WithLeaseDuration(*leaderElectionLeaseDuration)
217+
le.WithRenewDeadline(*leaderElectionRenewDeadline)
218+
le.WithRetryPeriod(*leaderElectionRetryPeriod)
213219
if err := le.Run(); err != nil {
214220
klog.Fatalf("failed to initialize leader election: %v", err)
215221
}

0 commit comments

Comments
 (0)