Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,16 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {

// Start the leader election and all required runnables.
{
ctx, cancel := context.WithCancel(context.Background())
// Create a context that inherits all keys from the parent context
// but can be cancelled independently for leader election management
baseCtx := context.WithoutCancel(ctx)
leaderCtx, cancel := context.WithCancel(baseCtx)
cm.leaderElectionCancel = cancel
if leaderElector != nil {
// Start the leader elector process
go func() {
leaderElector.Run(ctx)
<-ctx.Done()
leaderElector.Run(leaderCtx)
<-leaderCtx.Done()
close(cm.leaderElectionStopped)
}()
} else {
Expand Down