From 3fc9f8a9c193a6a7c5b5b6fde44f49196af4aff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Wed, 3 Jul 2024 16:05:38 +0200 Subject: [PATCH] Release leader election lease on exit (#3098) This will make rollouts and restarts much faster. --- .chloggen/feat_drop-lease-on-exit.yaml | 16 ++++++++++++++++ main.go | 16 +++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100755 .chloggen/feat_drop-lease-on-exit.yaml diff --git a/.chloggen/feat_drop-lease-on-exit.yaml b/.chloggen/feat_drop-lease-on-exit.yaml new file mode 100755 index 0000000000..a2cfbf1c58 --- /dev/null +++ b/.chloggen/feat_drop-lease-on-exit.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: operator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Release leader election lease on exit + +# One or more tracking issues related to the change +issues: [3058] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/main.go b/main.go index 798bbeada8..520e1f1f5a 100644 --- a/main.go +++ b/main.go @@ -249,13 +249,14 @@ func main() { Metrics: metricsserver.Options{ BindAddress: metricsAddr, }, - HealthProbeBindAddress: probeAddr, - LeaderElection: enableLeaderElection, - LeaderElectionID: "9f7554c3.opentelemetry.io", - LeaseDuration: &leaseDuration, - RenewDeadline: &renewDeadline, - RetryPeriod: &retryPeriod, - PprofBindAddress: pprofAddr, + HealthProbeBindAddress: probeAddr, + LeaderElection: enableLeaderElection, + LeaderElectionID: "9f7554c3.opentelemetry.io", + LeaderElectionReleaseOnCancel: true, + LeaseDuration: &leaseDuration, + RenewDeadline: &renewDeadline, + RetryPeriod: &retryPeriod, + PprofBindAddress: pprofAddr, WebhookServer: webhook.NewServer(webhook.Options{ Port: webhookPort, TLSOpts: optionsTlSOptsFuncs, @@ -427,6 +428,7 @@ func main() { } setupLog.Info("starting manager") + // NOTE: We enable LeaderElectionReleaseOnCancel, and to be safe we need to exit right after the manager does if err := mgr.Start(ctx); err != nil { setupLog.Error(err, "problem running manager") os.Exit(1)