Skip to content

Commit f006565

Browse files
committed
Leader election lease tunables
Set leader election LeaseDuration, RenewDealine and RetryPeriod via env variables. The values used are the ones mentioned as recommended in: https://github.com/openshift/enhancements/blob/master/CONVENTIONS.md#high-availability Jira: OSPRH-16335
1 parent f6b41da commit f006565

13 files changed

Lines changed: 65 additions & 10 deletions

File tree

apis/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250424140239-2d89c1d9f3ec
1717
github.com/openstack-k8s-operators/ironic-operator/api v0.6.1-0.20250423054051-4b1b486312a5
1818
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250420193521-f2b86a82d7e8
19-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0
19+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35
2020
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250423055245-3cb2ae8df6f0
2121
github.com/openstack-k8s-operators/manila-operator/api v0.6.1-0.20250421071803-b2385c65b8e5
2222
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250415060817-dc849adfa27e

apis/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ github.com/openstack-k8s-operators/ironic-operator/api v0.6.1-0.20250423054051-4
112112
github.com/openstack-k8s-operators/ironic-operator/api v0.6.1-0.20250423054051-4b1b486312a5/go.mod h1:Xla9BX9bX9/9SqV6g4fQEJUGiCLyd2JiR7Xk5fZJFmk=
113113
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250420193521-f2b86a82d7e8 h1:goExj6wO3m63qMWsavIR+IbnmkJ/H/kN5ypLDAfys+c=
114114
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250420193521-f2b86a82d7e8/go.mod h1:XbNobjVL9/ZRniHFpC8aqZUI//PM/Y9dvnoXTJ8RmPM=
115-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0 h1:L2YsApIsUga1ku2siRM/kPViRNk756q+g7jrweAHkdo=
116-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
115+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35 h1:dczrtvVjeDXUR3OhnUQRhVVnN14KX52qp0KXCulo8pA=
116+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
117117
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250423055245-3cb2ae8df6f0 h1:FAHrScvlj6w17wvcDhJ0ZnmraMrrOX1CxzvqZK595hA=
118118
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250423055245-3cb2ae8df6f0/go.mod h1:fesgTbs2j30Fhw2hebXkPgbeAIqG0Yk2oaeOklAInZg=
119119
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250423055245-3cb2ae8df6f0 h1:JejCQvZ28JmG87iGpy0tk8v4WJzZ07PIIAxXRpiMR9E=

bindata/operator/managers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ spec:
3535
value: 'true'
3636
{{ else }}
3737
value: 'false'
38+
{{ end }}
39+
{{ range $envName, $envValue := .ManagerOptions }}
40+
- name: {{ $envName }}
41+
value: {{ $envValue }}
3842
{{ end }}
3943
image: {{ $operatorImage }}
4044
livenessProbe:

bindata/operator/operator.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ spec:
7676
env:
7777
- name: OPENSTACK_RELEASE_VERSION
7878
value: '{{ .OpenstackReleaseVersion }}'
79+
- name: LEASE_DURATION
80+
value: 137
81+
- name: RENEW_DEADLINE
82+
value: 107
83+
- name: RETRY_PERIOD
84+
value: 26
7985
{{ range $envName, $envValue := .OpenStackServiceRelatedImages }}
8086
- name: {{ $envName }}
8187
value: {{ $envValue }}

bindata/operator/rabbit.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
valueFrom:
2828
fieldRef:
2929
fieldPath: metadata.namespace
30+
{{ range $envName, $envValue := .ManagerOptions }}
31+
- name: {{ $envName }}
32+
value: {{ $envValue }}
33+
{{ end }}
3034
image: {{ .RabbitmqImage }}
3135
name: operator
3236
ports:

cmd/operator/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242

4343
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4444

45+
"github.com/openstack-k8s-operators/lib-common/modules/common/operator"
4546
operatorv1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/operator/v1beta1"
4647
operatorcontrollers "github.com/openstack-k8s-operators/openstack-operator/controllers/operator"
4748
)
@@ -87,7 +88,7 @@ func main() {
8788
c.NextProtos = []string{"http/1.1"}
8889
}
8990

90-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
91+
options := ctrl.Options{
9192
Scheme: scheme,
9293
Metrics: metricsserver.Options{
9394
BindAddress: metricsAddr,
@@ -111,7 +112,15 @@ func main() {
111112
// if you are doing or is intended to do any operation such as perform cleanups
112113
// after the manager stops then its usage might be unsafe.
113114
// LeaderElectionReleaseOnCancel: true,
114-
})
115+
}
116+
117+
err = operator.SetManagerOptions(&options, setupLog)
118+
if err != nil {
119+
setupLog.Error(err, "unable to set manager options")
120+
os.Exit(1)
121+
}
122+
123+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
115124
if err != nil {
116125
setupLog.Error(err, "unable to start manager")
117126
os.Exit(1)

config/manager/manager.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ spec:
4444
env:
4545
- name: OPENSTACK_RELEASE_VERSION
4646
value: '{{ .OpenstackReleaseVersion }}'
47+
- name: LEASE_DURATION
48+
value: 137
49+
- name: RENEW_DEADLINE
50+
value: 107
51+
- name: RETRY_PERIOD
52+
value: 26
4753
envCustomImage: replace_me #NOTE: this is used via the Makefile to inject a custom template loop that kustomize won't allow
4854
image: '{{ .OperatorImage }}'
4955
name: manager

config/operator/managers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ spec:
3535
value: 'true'
3636
{{ else }}
3737
value: 'false'
38+
{{ end }}
39+
{{ range $envName, $envValue := .ManagerOptions }}
40+
- name: {{ $envName }}
41+
value: {{ $envValue }}
3842
{{ end }}
3943
image: {{ $operatorImage }}
4044
livenessProbe:

config/operator/rabbit.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
valueFrom:
2828
fieldRef:
2929
fieldPath: metadata.namespace
30+
{{ range $envName, $envValue := .ManagerOptions }}
31+
- name: {{ $envName }}
32+
value: {{ $envValue }}
33+
{{ end }}
3034
image: {{ .RabbitmqImage }}
3135
name: operator
3236
ports:

controllers/operator/openstack_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,18 @@ var (
7171
operatorImage string
7272
kubeRbacProxyImage string
7373
openstackReleaseVersion string
74+
managerOptions (map[string]*string)
7475
)
7576

7677
// SetupEnv -
7778
func SetupEnv() {
7879
envRelatedOperatorImages = make(map[string]*string)
7980
envRelatedOpenStackServiceImages = make(map[string]*string)
81+
managerOptionEnvNames := map[string]bool{
82+
"LEASE_DURATION": true,
83+
"RENEW_DEADLINE": true,
84+
"RETRY_PERIOD": true,
85+
}
8086
for _, name := range os.Environ() {
8187
envArr := strings.Split(name, "=")
8288

@@ -100,6 +106,8 @@ func SetupEnv() {
100106
operatorImage = envArr[1]
101107
} else if envArr[0] == "OPENSTACK_RELEASE_VERSION" {
102108
openstackReleaseVersion = envArr[1]
109+
} else if managerOptionEnvNames[envArr[0]] {
110+
managerOptions[envArr[0]] = &envArr[1]
103111
}
104112
}
105113
}
@@ -454,6 +462,7 @@ func (r *OpenStackReconciler) applyOperator(ctx context.Context, instance *opera
454462
data.Data["OperatorImage"] = operatorImage
455463
data.Data["KubeRbacProxyImage"] = kubeRbacProxyImage
456464
data.Data["OpenstackReleaseVersion"] = openstackReleaseVersion
465+
data.Data["ManagerOptions"] = managerOptions
457466
data.Data["OpenStackServiceRelatedImages"] = envRelatedOpenStackServiceImages
458467
return r.renderAndApply(ctx, instance, data, "operator", true)
459468
}

0 commit comments

Comments
 (0)