From 338ac2ad977b516da23e66e8d779bff28f555bff Mon Sep 17 00:00:00 2001 From: Mariano Cano <mariano.cano@gmail.com> Date: Thu, 22 Apr 2021 13:44:02 -0700 Subject: [PATCH] Add leader-election-id flag. Newer versions of the sigs.k8s.io controllers require a LeaderElectionId if the LeaderElection is enabled. This change adds a flag to set the id, or sets one by default if leader election is enabled. Signed-off-by: Mariano Cano <mariano.cano@gmail.com> --- main.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index e6b7017..72550b0 100644 --- a/main.go +++ b/main.go @@ -46,26 +46,32 @@ func init() { func main() { var metricsAddr string var enableLeaderElection bool + var leaderElectionID string var disableApprovedCheck bool + // Options for configuring logging + opts := zap.Options{} + opts.BindFlags(flag.CommandLine) + flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") + flag.StringVar(&leaderElectionID, "leader-election-id", "", + "The name of the resource that leader election will use for holding the leader lock.") flag.BoolVar(&disableApprovedCheck, "disable-approval-check", false, "Disables waiting for CertificateRequests to have an approved condition before signing.") - - // Options for configuring logging - opts := zap.Options{} - opts.BindFlags(flag.CommandLine) - flag.Parse() - ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) + if enableLeaderElection && leaderElectionID == "" { + leaderElectionID = "step-issuer-operator-lock" + } + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr, LeaderElection: enableLeaderElection, + LeaderElectionID: leaderElectionID, }) if err != nil { setupLog.Error(err, "unable to start manager") -- GitLab