Skip to content

Commit 9d75be8

Browse files
committed
Leader election lease tunables
Expose the leader election tunables for lease duration, renew deadline and retry period via environment variables. This is inspired by rabbitmq operator exposes the same. Jira: OSPRH-16335 Depends-On: openstack-k8s-operators/lib-common#627
1 parent 6520bec commit 9d75be8

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
github.com/google/go-cmp v0.7.0
7-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0
7+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35
88
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.0
99
k8s.io/api v0.29.15
1010
k8s.io/apimachinery v0.29.15

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7373
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7474
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7575
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
76-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0 h1:L2YsApIsUga1ku2siRM/kPViRNk756q+g7jrweAHkdo=
77-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
76+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35 h1:dczrtvVjeDXUR3OhnUQRhVVnN14KX52qp0KXCulo8pA=
77+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
7878
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.0 h1:iVGCAds5eVjKEoZS0KSBwYziLeLW3ZBs8PqPMrljPcg=
7979
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.0/go.mod h1:cGynoLGY9NfyIeWXI3zZ+hgZdHF3SUi8ht5ygZ8CmhI=
8080
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.6
99
github.com/onsi/ginkgo/v2 v2.20.1
1010
github.com/onsi/gomega v1.34.1
11-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0
11+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35
1212
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.0
1313
github.com/openstack-k8s-operators/test-operator/api v0.0.0-00010101000000-000000000000
1414
go.uber.org/zap v1.27.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7676
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
7777
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E=
7878
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
79-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0 h1:L2YsApIsUga1ku2siRM/kPViRNk756q+g7jrweAHkdo=
80-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250423055245-3cb2ae8df6f0/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
79+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35 h1:dczrtvVjeDXUR3OhnUQRhVVnN14KX52qp0KXCulo8pA=
80+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250505061650-7cb2f323fb35/go.mod h1:UwHXRIrMSPJD3lFqrA4oKmRXVLFQCRkLAj9x6KLEHiQ=
8181
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.0 h1:iVGCAds5eVjKEoZS0KSBwYziLeLW3ZBs8PqPMrljPcg=
8282
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.0/go.mod h1:cGynoLGY9NfyIeWXI3zZ+hgZdHF3SUi8ht5ygZ8CmhI=
8383
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4040

4141
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
42+
"github.com/openstack-k8s-operators/lib-common/modules/common/operator"
4243
testv1beta1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
4344
"github.com/openstack-k8s-operators/test-operator/controllers"
4445
//+kubebuilder:scaffold:imports
@@ -82,7 +83,7 @@ func main() {
8283
c.NextProtos = []string{"http/1.1"}
8384
}
8485

85-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
86+
options := ctrl.Options{
8687
Scheme: scheme,
8788
Metrics: metricsserver.Options{
8889
BindAddress: metricsAddr,
@@ -106,7 +107,15 @@ func main() {
106107
// if you are doing or is intended to do any operation such as perform cleanups
107108
// after the manager stops then its usage might be unsafe.
108109
// LeaderElectionReleaseOnCancel: true,
109-
})
110+
}
111+
112+
err := operator.SetManagerOptions(&options, setupLog)
113+
if err != nil {
114+
setupLog.Error(err, "unable to set manager options")
115+
os.Exit(1)
116+
}
117+
118+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
110119
if err != nil {
111120
setupLog.Error(err, "unable to start manager")
112121
os.Exit(1)

0 commit comments

Comments
 (0)