Skip to content

Commit 3f3c3e2

Browse files
Add leader election lease related flags (#421)
Add flags to the manager to be able to set various leader election configurations. These leader-election flags are supported by the [manager](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager#Options). Moreover most projects in the cluster-api umbrella already support them. Co-authored-by: Mohamed Chiheb Ben Jemaa <[email protected]>
1 parent fd3b7f0 commit 3f3c3e2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cmd/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net/http"
2626
"os"
27+
"time"
2728

2829
"github.com/go-logr/logr"
2930
"github.com/luthermonson/go-proxmox"
@@ -59,10 +60,13 @@ var (
5960
scheme = runtime.NewScheme()
6061
setupLog = ctrl.Log.WithName("setup")
6162

62-
metricsAddr string
63-
enableLeaderElection bool
64-
enableWebhooks bool
65-
probeAddr string
63+
metricsAddr string
64+
enableLeaderElection bool
65+
leaderElectionLeaseDuration time.Duration
66+
leaderElectionRenewDeadline time.Duration
67+
leaderElectionRetryPeriod time.Duration
68+
enableWebhooks bool
69+
probeAddr string
6670

6771
// ProxmoxURL env variable that defines the Proxmox host.
6872
ProxmoxURL string
@@ -101,6 +105,9 @@ func main() {
101105
}),
102106
HealthProbeBindAddress: probeAddr,
103107
LeaderElection: enableLeaderElection,
108+
LeaseDuration: &leaderElectionLeaseDuration,
109+
RenewDeadline: &leaderElectionRenewDeadline,
110+
RetryPeriod: &leaderElectionRetryPeriod,
104111
LeaderElectionID: "controller-leader-elect-capmox",
105112
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
106113
// when the Manager ends. This requires the binary to immediately end when the
@@ -232,6 +239,12 @@ func initFlagsAndEnv(fs *pflag.FlagSet) {
232239
fs.BoolVar(&enableLeaderElection, "leader-elect", false,
233240
"Enable leader election for controller manager. "+
234241
"Enabling this will ensure there is only one active controller manager.")
242+
fs.DurationVar(&leaderElectionLeaseDuration, "leader-elect-lease-duration", 15*time.Second,
243+
"Interval at which non-leader candidates will wait to force acquire leadership (duration string)")
244+
fs.DurationVar(&leaderElectionRenewDeadline, "leader-elect-renew-deadline", 10*time.Second,
245+
"Duration that the leading controller manager will retry refreshing leadership before giving up (duration string)")
246+
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second,
247+
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
235248
fs.BoolVar(&enableWebhooks, "enable-webhooks", true,
236249
"If true, run webhook server alongside manager")
237250

0 commit comments

Comments
 (0)