From 9a047cb4ffc02bd5a8ae4d5720abaddb252cd985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Wed, 31 May 2023 06:53:17 +0200 Subject: [PATCH] chore(leader-election): make leader election optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Clément Nussbaumer --- internal/cmd/cmd.go | 4 +++- internal/controller/csr_controller.go | 1 + internal/controller/testenv_setup_test.go | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 89de83c..c76c0b1 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -102,7 +102,7 @@ func CreateControllerManager(config *controller.Config, logger logr.Logger) ( mgrOptions := ctrl.Options{ MetricsBindAddress: config.MetricsAddr, HealthProbeBindAddress: config.ProbeAddr, - LeaderElection: true, + LeaderElection: config.LeaderElection, LeaderElectionID: "kubelet-csr-approver", } @@ -152,6 +152,7 @@ func prepareCmdlineConfig() *controller.Config { logLevel = fs.Int("level", 0, "level ranges from -5 (Fatal) to 10 (Verbose)") metricsAddr = fs.String("metrics-bind-address", ":8080", "address the metric endpoint binds to.") probeAddr = fs.String("health-probe-bind-address", ":8081", "address the probe endpoint binds to.") + leaderElection = fs.Bool("leader-election", false, "set this parameter to true to enable leader election") regexStr = fs.String("provider-regex", ".*", "provider-specified regex to validate CSR SAN names against. accepts everything unless specified") maxSec = fs.Int("max-expiration-sec", 367*24*3600, "maximum seconds a CSR can request a cerficate for. defaults to 367 days") bypassDNSResolution = fs.Bool("bypass-dns-resolution", false, "set this parameter to true to bypass DNS resolution checks") @@ -186,6 +187,7 @@ func prepareCmdlineConfig() *controller.Config { LogLevel: *logLevel, MetricsAddr: *metricsAddr, ProbeAddr: *probeAddr, + LeaderElection: *leaderElection, RegexStr: *regexStr, IPPrefixesStr: *ipPrefixesStr, BypassDNSResolution: *bypassDNSResolution, diff --git a/internal/controller/csr_controller.go b/internal/controller/csr_controller.go index 63bbe2e..c4d437a 100644 --- a/internal/controller/csr_controller.go +++ b/internal/controller/csr_controller.go @@ -46,6 +46,7 @@ type Config struct { LogLevel int MetricsAddr string ProbeAddr string + LeaderElection bool RegexStr string ProviderRegexp func(string) bool IPPrefixesStr string diff --git a/internal/controller/testenv_setup_test.go b/internal/controller/testenv_setup_test.go index 3dc2992..16d8373 100644 --- a/internal/controller/testenv_setup_test.go +++ b/internal/controller/testenv_setup_test.go @@ -204,6 +204,7 @@ func packageSetup() { } testingConfig := controller.Config{ + LeaderElection: true, RegexStr: `^[\w-]*\.test\.ch$`, MaxExpirationSeconds: 367 * 24 * 3600, AllowedDNSNames: 3,