Skip to content

Commit 998c61b

Browse files
committed
feat: add leader-election-lease-duration flag
Signed-off-by: gjbravi <[email protected]>
1 parent e1d32f4 commit 998c61b

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

pkg/config/runtime_config.go

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,29 @@ import (
1818
)
1919

2020
const (
21-
flagMetricsBindAddr = "metrics-bind-addr"
22-
flagHealthProbeBindAddr = "health-probe-bind-addr"
23-
flagWebhookBindPort = "webhook-bind-port"
24-
flagEnableLeaderElection = "enable-leader-election"
25-
flagLeaderElectionID = "leader-election-id"
26-
flagLeaderElectionNamespace = "leader-election-namespace"
27-
flagWatchNamespace = "watch-namespace"
28-
flagSyncPeriod = "sync-period"
29-
flagKubeconfig = "kubeconfig"
30-
flagWebhookCertDir = "webhook-cert-dir"
31-
flagWebhookCertName = "webhook-cert-file"
32-
flagWebhookKeyName = "webhook-key-file"
21+
flagMetricsBindAddr = "metrics-bind-addr"
22+
flagHealthProbeBindAddr = "health-probe-bind-addr"
23+
flagWebhookBindPort = "webhook-bind-port"
24+
flagEnableLeaderElection = "enable-leader-election"
25+
flagLeaderElectionID = "leader-election-id"
26+
flagLeaderElectionNamespace = "leader-election-namespace"
27+
flagLeaderElectionLeaseDuration = "leader-election-lease-duration"
28+
flagWatchNamespace = "watch-namespace"
29+
flagSyncPeriod = "sync-period"
30+
flagKubeconfig = "kubeconfig"
31+
flagWebhookCertDir = "webhook-cert-dir"
32+
flagWebhookCertName = "webhook-cert-file"
33+
flagWebhookKeyName = "webhook-key-file"
3334

34-
defaultKubeconfig = ""
35-
defaultLeaderElectionID = "aws-load-balancer-controller-leader"
36-
defaultLeaderElectionNamespace = ""
37-
defaultWatchNamespace = corev1.NamespaceAll
38-
defaultMetricsAddr = ":8080"
39-
defaultHealthProbeBindAddress = ":61779"
40-
defaultSyncPeriod = 10 * time.Hour
41-
defaultWebhookBindPort = 9443
35+
defaultKubeconfig = ""
36+
defaultLeaderElectionID = "aws-load-balancer-controller-leader"
37+
defaultLeaderElectionNamespace = ""
38+
defaultLeaderElectionLeaseDuration = 15 * time.Second
39+
defaultWatchNamespace = corev1.NamespaceAll
40+
defaultMetricsAddr = ":8080"
41+
defaultHealthProbeBindAddress = ":61779"
42+
defaultSyncPeriod = 10 * time.Hour
43+
defaultWebhookBindPort = 9443
4244
// High enough QPS to fit all expected use cases. QPS=0 is not set here, because
4345
// client code is overriding it.
4446
defaultQPS = 1e6
@@ -52,19 +54,20 @@ const (
5254

5355
// RuntimeConfig stores the configuration for the controller-runtime
5456
type RuntimeConfig struct {
55-
APIServer string
56-
KubeConfig string
57-
WebhookBindPort int
58-
MetricsBindAddress string
59-
HealthProbeBindAddress string
60-
EnableLeaderElection bool
61-
LeaderElectionID string
62-
LeaderElectionNamespace string
63-
WatchNamespace string
64-
SyncPeriod time.Duration
65-
WebhookCertDir string
66-
WebhookCertName string
67-
WebhookKeyName string
57+
APIServer string
58+
KubeConfig string
59+
WebhookBindPort int
60+
MetricsBindAddress string
61+
HealthProbeBindAddress string
62+
EnableLeaderElection bool
63+
LeaderElectionID string
64+
LeaderElectionNamespace string
65+
LeaderElectionLeaseDuration time.Duration
66+
WatchNamespace string
67+
SyncPeriod time.Duration
68+
WebhookCertDir string
69+
WebhookCertName string
70+
WebhookKeyName string
6871
}
6972

7073
// BindFlags binds the command line flags to the fields in the config object
@@ -91,7 +94,8 @@ func (c *RuntimeConfig) BindFlags(fs *pflag.FlagSet) {
9194
fs.StringVar(&c.WebhookCertDir, flagWebhookCertDir, defaultWebhookCertDir, "WebhookCertDir is the directory that contains the webhook server key and certificate.")
9295
fs.StringVar(&c.WebhookCertName, flagWebhookCertName, defaultWebhookCertName, "WebhookCertName is the webhook server certificate name.")
9396
fs.StringVar(&c.WebhookKeyName, flagWebhookKeyName, defaultWebhookKeyName, "WebhookKeyName is the webhook server key name.")
94-
97+
fs.DurationVar(&c.LeaderElectionLeaseDuration, flagLeaderElectionLeaseDuration, defaultLeaderElectionLeaseDuration,
98+
"The duration that non-leader candidates will wait to force acquire leadership.")
9599
}
96100

97101
// BuildRestConfig builds the REST config for the controller runtime
@@ -122,6 +126,7 @@ func BuildRuntimeOptions(rtCfg RuntimeConfig, scheme *runtime.Scheme) ctrl.Optio
122126
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
123127
LeaderElectionID: rtCfg.LeaderElectionID,
124128
LeaderElectionNamespace: rtCfg.LeaderElectionNamespace,
129+
LeaseDuration: &rtCfg.LeaderElectionLeaseDuration,
125130
Cache: cache.Options{
126131
SyncPeriod: &rtCfg.SyncPeriod,
127132
},

0 commit comments

Comments
 (0)