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 }