Skip to content

Commit

Permalink
✨ Allow configuring LeaderElectionReleaseOnCancel
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman committed Aug 13, 2020
1 parent 5ef5ed9 commit 93e6db8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ type controllerManager struct {
// resourceLock forms the basis for leader election
resourceLock resourcelock.Interface

// leaderElectionReleaseOnCancel defines if the manager should step back from the leader lease
// on shutdown
leaderElectionReleaseOnCancel bool

// mapper is used to map resources to kind, and map kind and version.
mapper meta.RESTMapper

Expand Down Expand Up @@ -640,6 +644,7 @@ func (cm *controllerManager) startLeaderElection() (err error) {
},
OnStoppedLeading: cm.onStoppedLeading,
},
ReleaseOnCancel: cm.leaderElectionReleaseOnCancel,
})
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ type Options struct {
// that is used to build the leader election client.
LeaderElectionConfig *rest.Config

// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader doesn't have to wait
// LeaseDuration time first.
LeaderElectionReleaseOnCancel bool

// LeaseDuration is the duration that non-leader candidates will
// wait to force acquire leadership. This is measured against time of
// last observed ack. Default is 15 seconds.
Expand Down

0 comments on commit 93e6db8

Please sign in to comment.