Controller: Make Leader Election TTL configurable. (#11142)
* feature(leader_ttl): feature to customize ttl to leader be re-elected * fix(review): docs
This commit is contained in:
parent
aedb13c9fa
commit
7c8af4928b
9 changed files with 93 additions and 8 deletions
|
|
@ -91,6 +91,7 @@ type Configuration struct {
|
|||
UpdateStatus bool
|
||||
UseNodeInternalIP bool
|
||||
ElectionID string
|
||||
ElectionTTL time.Duration
|
||||
UpdateStatusOnShutdown bool
|
||||
|
||||
HealthCheckHost string
|
||||
|
|
|
|||
|
|
@ -274,8 +274,9 @@ func (n *NGINXController) Start() {
|
|||
if !n.cfg.DisableLeaderElection {
|
||||
electionID := n.cfg.ElectionID
|
||||
setupLeaderElection(&leaderElectionConfig{
|
||||
Client: n.cfg.Client,
|
||||
ElectionID: electionID,
|
||||
Client: n.cfg.Client,
|
||||
ElectionID: electionID,
|
||||
ElectionTTL: n.cfg.ElectionTTL,
|
||||
OnStartedLeading: func(stopCh chan struct{}) {
|
||||
if n.syncStatus != nil {
|
||||
go n.syncStatus.Run(stopCh)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ import (
|
|||
type leaderElectionConfig struct {
|
||||
Client clientset.Interface
|
||||
|
||||
ElectionID string
|
||||
ElectionID string
|
||||
ElectionTTL time.Duration
|
||||
|
||||
OnStartedLeading func(chan struct{})
|
||||
OnStoppedLeading func()
|
||||
|
|
@ -107,13 +108,11 @@ func setupLeaderElection(config *leaderElectionConfig) {
|
|||
LockConfig: resourceLockConfig,
|
||||
}
|
||||
|
||||
ttl := 30 * time.Second
|
||||
|
||||
elector, err = leaderelection.NewLeaderElector(leaderelection.LeaderElectionConfig{
|
||||
Lock: lock,
|
||||
LeaseDuration: ttl,
|
||||
RenewDeadline: ttl / 2,
|
||||
RetryPeriod: ttl / 4,
|
||||
LeaseDuration: config.ElectionTTL,
|
||||
RenewDeadline: config.ElectionTTL / 2,
|
||||
RetryPeriod: config.ElectionTTL / 4,
|
||||
|
||||
Callbacks: callbacks,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue