From c94baacfff6a7b91de69764b0d3650a3a854e271 Mon Sep 17 00:00:00 2001 From: googs1025 Date: Fri, 4 Oct 2024 00:21:42 +0800 Subject: [PATCH] fix(leaderelection): nil check in OnStoppedLeading func --- .../controller/leaderelection/run_with_leaderelection.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/controlplane/controller/leaderelection/run_with_leaderelection.go b/pkg/controlplane/controller/leaderelection/run_with_leaderelection.go index f34c5a2e405fb..0b73170d1f724 100644 --- a/pkg/controlplane/controller/leaderelection/run_with_leaderelection.go +++ b/pkg/controlplane/controller/leaderelection/run_with_leaderelection.go @@ -50,7 +50,9 @@ func RunWithLeaderElection(ctx context.Context, config *rest.Config, newRunnerFn run(ctx, 1) }, OnStoppedLeading: func() { - cancel() + if cancel != nil { + cancel() + } }, }