From 45acf9a3096d5fb19ca8e86220b1aa08ffab9d64 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..d93aab0016a 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 whenever + // flgs.EnableLeaderElection is true. + LeaderElectionReleaseOnCancel: flgs.EnableLeaderElection, + HealthProbeBindAddress: flgs.HealthAddr, + Metrics: getMetricsOpts(flgs), WebhookServer: webhook.NewServer(webhook.Options{ Port: flgs.WebhookPort, CertDir: flgs.WebhookCertDir,