Skip to content

Commit a56f421

Browse files
Copy all parent context values to leader elector's context
1 parent 961fc2c commit a56f421

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/manager/internal.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,16 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {
446446

447447
// Start the leader election and all required runnables.
448448
{
449-
ctx, cancel := context.WithCancel(context.Background())
449+
// Create a context that inherits all keys from the parent context
450+
// but can be cancelled independently for leader election management
451+
baseCtx := context.WithoutCancel(ctx)
452+
leaderCtx, cancel := context.WithCancel(baseCtx)
450453
cm.leaderElectionCancel = cancel
451454
if leaderElector != nil {
452455
// Start the leader elector process
453456
go func() {
454-
leaderElector.Run(ctx)
455-
<-ctx.Done()
457+
leaderElector.Run(leaderCtx)
458+
<-leaderCtx.Done()
456459
close(cm.leaderElectionStopped)
457460
}()
458461
} else {

0 commit comments

Comments
 (0)