From 4a3c3f3855e42958df01fb342e2f7e52c33a9195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=89=E5=8D=97?= Date: Tue, 25 Jun 2024 17:37:06 +0800 Subject: [PATCH] MOD:add a new config in manager.Mew to set on stopped leading function --- pkg/manager/manager.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 3166f4818f..2ef2506f7b 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -33,6 +33,7 @@ import ( "k8s.io/client-go/tools/leaderelection/resourcelock" "k8s.io/client-go/tools/record" "k8s.io/utils/ptr" + metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/cache" @@ -201,6 +202,10 @@ type Options struct { // LeaseDuration time first. LeaderElectionReleaseOnCancel bool + // OnStoppedLeading is callled when the leader election lease is lost. + // It can be overridden for tests. + OnStoppedLeading func() + // LeaderElectionResourceLockInterface allows to provide a custom resourcelock.Interface that was created outside // of the controller-runtime. If this value is set the options LeaderElectionID, LeaderElectionNamespace, // LeaderElectionResourceLock, LeaseDuration, RenewDeadline and RetryPeriod will be ignored. This can be useful if you @@ -441,6 +446,7 @@ func New(config *rest.Config, options Options) (Manager, error) { internalProceduresStop: make(chan struct{}), leaderElectionStopped: make(chan struct{}), leaderElectionReleaseOnCancel: options.LeaderElectionReleaseOnCancel, + onStoppedLeading: options.OnStoppedLeading, }, nil }