Skip to content

Commit

Permalink
Log real reason of shutdown of the controller. (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
apasyniuk authored Sep 11, 2023
1 parent 4778713 commit ec04738
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ func runWithLeaderElection(
runFunc(ctx)
},
OnStoppedLeading: func() {
// This method is always called(even if it was not a leader):
// - when controller shuts dow (for example because of SIGTERM)
// - we actually lost leader
// So we need to check what whas reason of acutally stopping.
if err := ctx.Err(); err != nil {
log.Infof("main context done, stopping controller: %v", err)
return
}
log.Infof("leader lost: %s", id)
// We don't need to exit here.
// Leader "on started leading" receive a context that gets cancelled when you're no longer the leader.
Expand Down

0 comments on commit ec04738

Please sign in to comment.