Skip to content

Commit

Permalink
Merge pull request #4845 from nikParasyr/leader_elect
Browse files Browse the repository at this point in the history
✨ Add flags for leaderElection timeouts
  • Loading branch information
k8s-ci-robot authored Mar 22, 2024
2 parents a8d7162 + 34be445 commit 2e16f31
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,23 @@ func init() {
}

var (
enableLeaderElection bool
leaderElectionNamespace string
watchNamespace string
watchFilterValue string
profilerAddress string
awsClusterConcurrency int
instanceStateConcurrency int
awsMachineConcurrency int
waitInfraPeriod time.Duration
syncPeriod time.Duration
webhookPort int
webhookCertDir string
healthAddr string
serviceEndpoints string
enableLeaderElection bool
leaderElectionLeaseDuration time.Duration
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
leaderElectionNamespace string
watchNamespace string
watchFilterValue string
profilerAddress string
awsClusterConcurrency int
instanceStateConcurrency int
awsMachineConcurrency int
waitInfraPeriod time.Duration
syncPeriod time.Duration
webhookPort int
webhookCertDir string
healthAddr string
serviceEndpoints string

// maxEKSSyncPeriod is the maximum allowed duration for the sync-period flag when using EKS. It is set to 10 minutes
// because during resync it will create a new AWS auth token which can a maximum life of 15 minutes and this ensures
Expand Down Expand Up @@ -171,6 +174,9 @@ func main() {
Scheme: scheme,
Metrics: diagnosticsOpts,
LeaderElection: enableLeaderElection,
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &leaderElectionRenewDeadline,
RetryPeriod: &leaderElectionRetryPeriod,
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionID: "controller-leader-elect-capa",
LeaderElectionNamespace: leaderElectionNamespace,
Expand Down Expand Up @@ -495,6 +501,27 @@ func initFlags(fs *pflag.FlagSet) {
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.",
)

fs.DurationVar(
&leaderElectionLeaseDuration,
"leader-elect-lease-duration",
15*time.Second,
"Interval at which non-leader candidates will wait to force acquire leadership (duration string)",
)

fs.DurationVar(
&leaderElectionRenewDeadline,
"leader-elect-renew-deadline",
10*time.Second,
"Duration that the leading controller manager will retry refreshing leadership before giving up (duration string)",
)

fs.DurationVar(
&leaderElectionRetryPeriod,
"leader-elect-retry-period",
2*time.Second,
"Duration the LeaderElector clients should wait between tries of actions (duration string)",
)

fs.StringVar(
&watchNamespace,
"namespace",
Expand Down

0 comments on commit 2e16f31

Please sign in to comment.