Skip to content

Commit 34be445

Browse files
committed
Add flags for leaderElection timeouts
Add flags on manager to configure leaseDuration, renewDeadline and RetryPeriod for leader election. Set defaults based on cluster-api.
1 parent f0a5ecf commit 34be445

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

main.go

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,23 @@ func init() {
9191
}
9292

9393
var (
94-
enableLeaderElection bool
95-
leaderElectionNamespace string
96-
watchNamespace string
97-
watchFilterValue string
98-
profilerAddress string
99-
awsClusterConcurrency int
100-
instanceStateConcurrency int
101-
awsMachineConcurrency int
102-
waitInfraPeriod time.Duration
103-
syncPeriod time.Duration
104-
webhookPort int
105-
webhookCertDir string
106-
healthAddr string
107-
serviceEndpoints string
94+
enableLeaderElection bool
95+
leaderElectionLeaseDuration time.Duration
96+
leaderElectionRenewDeadline time.Duration
97+
leaderElectionRetryPeriod time.Duration
98+
leaderElectionNamespace string
99+
watchNamespace string
100+
watchFilterValue string
101+
profilerAddress string
102+
awsClusterConcurrency int
103+
instanceStateConcurrency int
104+
awsMachineConcurrency int
105+
waitInfraPeriod time.Duration
106+
syncPeriod time.Duration
107+
webhookPort int
108+
webhookCertDir string
109+
healthAddr string
110+
serviceEndpoints string
108111

109112
// maxEKSSyncPeriod is the maximum allowed duration for the sync-period flag when using EKS. It is set to 10 minutes
110113
// because during resync it will create a new AWS auth token which can a maximum life of 15 minutes and this ensures
@@ -170,6 +173,9 @@ func main() {
170173
Scheme: scheme,
171174
Metrics: diagnosticsOpts,
172175
LeaderElection: enableLeaderElection,
176+
LeaseDuration: &leaderElectionLeaseDuration,
177+
RenewDeadline: &leaderElectionRenewDeadline,
178+
RetryPeriod: &leaderElectionRetryPeriod,
173179
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
174180
LeaderElectionID: "controller-leader-elect-capa",
175181
LeaderElectionNamespace: leaderElectionNamespace,
@@ -494,6 +500,27 @@ func initFlags(fs *pflag.FlagSet) {
494500
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.",
495501
)
496502

503+
fs.DurationVar(
504+
&leaderElectionLeaseDuration,
505+
"leader-elect-lease-duration",
506+
15*time.Second,
507+
"Interval at which non-leader candidates will wait to force acquire leadership (duration string)",
508+
)
509+
510+
fs.DurationVar(
511+
&leaderElectionRenewDeadline,
512+
"leader-elect-renew-deadline",
513+
10*time.Second,
514+
"Duration that the leading controller manager will retry refreshing leadership before giving up (duration string)",
515+
)
516+
517+
fs.DurationVar(
518+
&leaderElectionRetryPeriod,
519+
"leader-elect-retry-period",
520+
2*time.Second,
521+
"Duration the LeaderElector clients should wait between tries of actions (duration string)",
522+
)
523+
497524
fs.StringVar(
498525
&watchNamespace,
499526
"namespace",

0 commit comments

Comments
 (0)