diff --git a/tools/leaderelection/leaderelection.go b/tools/leaderelection/leaderelection.go index 777bcd87..4a532968 100644 --- a/tools/leaderelection/leaderelection.go +++ b/tools/leaderelection/leaderelection.go @@ -195,10 +195,11 @@ type LeaderElector struct { // Run starts the leader election loop func (le *LeaderElector) Run(ctx context.Context) { + defer runtime.HandleCrash() defer func() { - runtime.HandleCrash() le.config.Callbacks.OnStoppedLeading() }() + if !le.acquire(ctx) { return // ctx signalled done }