From ba715c782bf9cedc0d9944052ac1d4af0f07418c Mon Sep 17 00:00:00 2001 From: Matthew Christopher Date: Thu, 5 Sep 2024 13:30:09 -0700 Subject: [PATCH] Release lease when the pod is terminated Closes #4226. --- v2/cmd/controller/app/setup.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/v2/cmd/controller/app/setup.go b/v2/cmd/controller/app/setup.go index d28129f9e8d..9d9c7bce494 100644 --- a/v2/cmd/controller/app/setup.go +++ b/v2/cmd/controller/app/setup.go @@ -76,12 +76,16 @@ func SetupControllerManager(ctx context.Context, setupLog logr.Logger, flgs *Fla k8sConfig := ctrl.GetConfigOrDie() mgr, err := ctrl.NewManager(k8sConfig, ctrl.Options{ - Scheme: scheme, - NewCache: cacheFunc, - LeaderElection: flgs.EnableLeaderElection, - LeaderElectionID: "controllers-leader-election-azinfra-generated", - HealthProbeBindAddress: flgs.HealthAddr, - Metrics: getMetricsOpts(flgs), + Scheme: scheme, + NewCache: cacheFunc, + LeaderElection: flgs.EnableLeaderElection, + LeaderElectionID: "controllers-leader-election-azinfra-generated", + // It's only safe to set LeaderElectionReleaseOnCancel to true if the manager binary ends + // when the manager exits. This is the case with us today, so we set this to true to + // enable faster lease transfers. + LeaderElectionReleaseOnCancel: true, + HealthProbeBindAddress: flgs.HealthAddr, + Metrics: getMetricsOpts(flgs), WebhookServer: webhook.NewServer(webhook.Options{ Port: flgs.WebhookPort, CertDir: flgs.WebhookCertDir,