From a56f421d83c5317b13f8d323b1fe1c0e1eb6bbd4 Mon Sep 17 00:00:00 2001 From: Manoj Sudheendra Date: Fri, 26 Sep 2025 16:03:37 -0400 Subject: [PATCH] Copy all parent context values to leader elector's context --- pkg/manager/internal.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/manager/internal.go b/pkg/manager/internal.go index a9f91cbdd5..a2c3e5324d 100644 --- a/pkg/manager/internal.go +++ b/pkg/manager/internal.go @@ -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 {