Skip to content

Commit 0e51e93

Browse files
committed
Allow the Operator lease duration and renewal timeout to be configured
1 parent e5fe8c9 commit 0e51e93

File tree

2 files changed

+64
-39
lines changed

2 files changed

+64
-39
lines changed

pkg/operator/operator.go

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,47 @@ const (
4949
DefaultMutatingWebhookName = "coherence-operator-mutating-webhook-configuration"
5050
DefaultValidatingWebhookName = "coherence-operator-validating-webhook-configuration"
5151

52-
FlagCACertRotateBefore = "ca-cert-rotate-before"
53-
FlagCACertValidity = "ca-cert-validity"
54-
FlagCertType = "cert-type"
55-
FlagCertIssuer = "cert-issuer"
56-
FlagCoherenceImage = "coherence-image"
57-
FlagCRD = "install-crd"
58-
FlagJobCRD = "install-job-crd"
59-
FlagEnableCoherenceJobs = "enable-jobs"
60-
FlagDevMode = "coherence-dev-mode"
61-
FlagCipherDenyList = "cipher-deny-list"
62-
FlagCipherAllowList = "cipher-allow-list"
63-
FlagConfig = "config"
64-
FlagConfigType = "config-type"
65-
FlagDryRun = "dry-run"
66-
FlagEnableWebhook = "enable-webhook"
67-
FlagEnableHttp2 = "enable-http2"
68-
FlagGlobalAnnotation = "global-annotation"
69-
FlagGlobalLabel = "global-label"
70-
FlagHealthAddress = "health-addr"
71-
FlagLeaderElection = "enable-leader-election"
72-
FlagMetricsAddress = "metrics-addr"
73-
FlagMutatingWebhookName = "mutating-webhook-name"
74-
FlagOperatorNamespace = "operator-namespace"
75-
FlagNodeLookupEnabled = "node-lookup-enabled"
76-
FlagRackLabel = "rack-label"
77-
FlagRestHost = "rest-host"
78-
FlagRestPort = "rest-port"
79-
FlagSecureMetrics = "metrics-secure"
80-
FlagServiceName = "service-name"
81-
FlagServicePort = "service-port"
82-
FlagSiteLabel = "site-label"
83-
FlagSkipServiceSuspend = "skip-service-suspend"
84-
FlagOperatorImage = "operator-image"
85-
FlagValidatingWebhookName = "validating-webhook-name"
86-
FlagWebhookCertDir = "webhook-cert-dir"
87-
FlagWebhookSecret = "webhook-secret"
88-
FlagWebhookService = "webhook-service"
89-
FlagEnvVar = "env"
90-
FlagJvmArg = "jvm"
52+
FlagCACertRotateBefore = "ca-cert-rotate-before"
53+
FlagCACertValidity = "ca-cert-validity"
54+
FlagCertType = "cert-type"
55+
FlagCertIssuer = "cert-issuer"
56+
FlagCoherenceImage = "coherence-image"
57+
FlagCRD = "install-crd"
58+
FlagJobCRD = "install-job-crd"
59+
FlagEnableCoherenceJobs = "enable-jobs"
60+
FlagDevMode = "coherence-dev-mode"
61+
FlagCipherDenyList = "cipher-deny-list"
62+
FlagCipherAllowList = "cipher-allow-list"
63+
FlagConfig = "config"
64+
FlagConfigType = "config-type"
65+
FlagDryRun = "dry-run"
66+
FlagEnableWebhook = "enable-webhook"
67+
FlagEnableHttp2 = "enable-http2"
68+
FlagGlobalAnnotation = "global-annotation"
69+
FlagGlobalLabel = "global-label"
70+
FlagHealthAddress = "health-addr"
71+
FlagLeaderElection = "enable-leader-election"
72+
FlagLeaderElectionDuration = "leader-election-duration"
73+
FlagLeaderElectionRenew = "leader-election-renew-timeout"
74+
FlagMetricsAddress = "metrics-addr"
75+
FlagMutatingWebhookName = "mutating-webhook-name"
76+
FlagOperatorNamespace = "operator-namespace"
77+
FlagNodeLookupEnabled = "node-lookup-enabled"
78+
FlagRackLabel = "rack-label"
79+
FlagRestHost = "rest-host"
80+
FlagRestPort = "rest-port"
81+
FlagSecureMetrics = "metrics-secure"
82+
FlagServiceName = "service-name"
83+
FlagServicePort = "service-port"
84+
FlagSiteLabel = "site-label"
85+
FlagSkipServiceSuspend = "skip-service-suspend"
86+
FlagOperatorImage = "operator-image"
87+
FlagValidatingWebhookName = "validating-webhook-name"
88+
FlagWebhookCertDir = "webhook-cert-dir"
89+
FlagWebhookSecret = "webhook-secret"
90+
FlagWebhookService = "webhook-service"
91+
FlagEnvVar = "env"
92+
FlagJvmArg = "jvm"
9193

9294
// EnvVarWatchNamespace is the environment variable to use to set the watch namespace(s)
9395
EnvVarWatchNamespace = "WATCH_NAMESPACE"
@@ -304,6 +306,17 @@ func SetupFlags(cmd *cobra.Command, v *viper.Viper) {
304306
FlagCipherAllowList,
305307
nil,
306308
"A list of TLS cipher names to be enabled (if a cipher appears in this list and the deny list it will be disabled)")
309+
cmd.Flags().Duration(
310+
FlagLeaderElectionDuration,
311+
time.Second*30,
312+
"The value the Operator uses for the leadership lease duration. "+
313+
"Setting this value too low can cause Pod restarts as the leader may lose leadership. "+
314+
"If the value entered is less than 10s, then 10s will be used")
315+
cmd.Flags().Duration(
316+
FlagLeaderElectionRenew,
317+
time.Second*20,
318+
"The duration the Operator uses for the leadership lease renewal timeout. "+
319+
"If the value entered is less than 10s, then 10s will be used")
307320

308321
// enable using dashed notation in flags and underscores in env
309322
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

pkg/runner/cmd_operator.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3535
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3636
hooks "sigs.k8s.io/controller-runtime/pkg/webhook"
37+
"time"
3738
// +kubebuilder:scaffold:imports
3839
)
3940

@@ -148,13 +149,24 @@ func execute(v *viper.Viper) error {
148149
TLSOpts: tlsOpts,
149150
})
150151

152+
duration := viper.GetDuration(operator.FlagLeaderElectionDuration)
153+
if duration < time.Second*10 {
154+
duration = time.Second * 10
155+
}
156+
renew := viper.GetDuration(operator.FlagLeaderElectionRenew)
157+
if renew < time.Second*10 {
158+
renew = time.Second * 10
159+
}
160+
151161
options := ctrl.Options{
152162
Scheme: scheme,
153163
HealthProbeBindAddress: viper.GetString(operator.FlagHealthAddress),
154164
Metrics: metricsServerOptions,
155165
WebhookServer: webhookServer,
156166
LeaderElection: viper.GetBool(operator.FlagLeaderElection),
157167
LeaderElectionID: lockName,
168+
LeaseDuration: &duration,
169+
RenewDeadline: &renew,
158170
Controller: config.Controller{
159171
SkipNameValidation: ptr.To(dryRun),
160172
},

0 commit comments

Comments
 (0)