Skip to content

Commit cf246c9

Browse files
author
Jonathan Knight
authored
Allow the Operator lease duration and renewal timeout to be configured (oracle#773)
1 parent d797ef0 commit cf246c9

File tree

4 files changed

+96
-39
lines changed

4 files changed

+96
-39
lines changed

helm-charts/coherence-operator/templates/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ spec:
189189
{{- end }}
190190
{{- range .Values.cipherDenyList }}
191191
- --cipher-deny-list={{ . }}
192+
{{- end }}
193+
{{- if .Values.leaderElectionDuration }}
194+
- --leader-election-duration={{ .Values.leaderElectionDuration | quote }}
195+
{{- end }}
196+
{{- if .Values.leaderElectionRenewTimeout }}
197+
- --leader-election-renew-timeout={{ .Values.leaderElectionRenewTimeout | quote }}
192198
{{- end }}
193199
command:
194200
- "/files/runner"

helm-charts/coherence-operator/values.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,34 @@ allowCoherenceJobs: true
225225
# The CRDs must be manually installed before the Operator can be installed.
226226
installCrd: true
227227

228+
# The list of allowed TLS cipher suite names.
228229
cipherAllowList: []
229230

231+
# The list of disallowed TLS cipher suite names.
230232
cipherDenyList: []
231233

234+
# This value is used to set the `GODEBUG` environment variables.
235+
# The `fips` value is unset by default, if set it must be one of the values, "off", "on" or "only".
236+
# If `fips` is set to any other value, the chart will fail to install.
232237
fips:
238+
239+
# The value that the Operator will use for the leadership lease duration.
240+
# This is a string value that should be a valid Go Duration string.
241+
#
242+
# The default value is 30 seconds. The only reason to change this is in some environments
243+
# that may be particularly slow and would need a larger value due to loss of leadership issues
244+
#
245+
# Normally this will be a number of seconds. For example, 30 seconds is "30s" and
246+
# there would not be any reason to have values in minutes or hours.
247+
leaderElectionDuration:
248+
249+
# The value that the Operator will use for the leadership lease renewal timeout.
250+
# This is a string value that should be a valid Go Duration string.
251+
#
252+
# The default value is 20 seconds. The only reason to change this is in some environments
253+
# that may be particularly slow and would need a larger value due to loss of leadership issues
254+
#
255+
# Normally this will be a number of seconds. For example, 30 seconds is "30s" and
256+
# there would not be any reason to have values in minutes or hours.
257+
leaderElectionRenewTimeout:
258+

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)