Skip to content

Commit d12bb87

Browse files
authored
Merge pull request #1126 from alvaroaleman/allow-step-down
✨ Allow configuring LeaderElectionReleaseOnCancel
2 parents 03e4763 + 93e6db8 commit d12bb87

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pkg/manager/internal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ type controllerManager struct {
9494
// resourceLock forms the basis for leader election
9595
resourceLock resourcelock.Interface
9696

97+
// leaderElectionReleaseOnCancel defines if the manager should step back from the leader lease
98+
// on shutdown
99+
leaderElectionReleaseOnCancel bool
100+
97101
// mapper is used to map resources to kind, and map kind and version.
98102
mapper meta.RESTMapper
99103

@@ -640,6 +644,7 @@ func (cm *controllerManager) startLeaderElection() (err error) {
640644
},
641645
OnStoppedLeading: cm.onStoppedLeading,
642646
},
647+
ReleaseOnCancel: cm.leaderElectionReleaseOnCancel,
643648
})
644649
if err != nil {
645650
return err

pkg/manager/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ type Options struct {
154154
// that is used to build the leader election client.
155155
LeaderElectionConfig *rest.Config
156156

157+
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
158+
// when the Manager ends. This requires the binary to immediately end when the
159+
// Manager is stopped, otherwise this setting is unsafe. Setting this significantly
160+
// speeds up voluntary leader transitions as the new leader doesn't have to wait
161+
// LeaseDuration time first.
162+
LeaderElectionReleaseOnCancel bool
163+
157164
// LeaseDuration is the duration that non-leader candidates will
158165
// wait to force acquire leadership. This is measured against time of
159166
// last observed ack. Default is 15 seconds.

0 commit comments

Comments
 (0)