Skip to content

Commit

Permalink
quit leader election if context was cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
adel121 committed Dec 18, 2024
1 parent 332025d commit 364ceb6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/util/kubernetes/apiserver/leaderelection/leaderelection.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,15 @@ func (le *LeaderEngine) EnsureLeaderElectionRuns() error {

func (le *LeaderEngine) runLeaderElection() {
for {
log.Infof("Starting leader election process for %q...", le.HolderIdentity)
le.leaderElector.Run(le.ctx)
log.Info("Leader election lost")
select {
case <-le.ctx.Done():
log.Infof("Quitting leader election process: context was cancelled")
return
default:
log.Infof("Starting leader election process for %q...", le.HolderIdentity)
le.leaderElector.Run(le.ctx)
log.Info("Leader election lost")
}
}
}

Expand Down

0 comments on commit 364ceb6

Please sign in to comment.