Skip to content

Commit

Permalink
Revert "feat: remove leader election for operator (opendatahub-io#1000)…
Browse files Browse the repository at this point in the history
…" (opendatahub-io#1153)

* Revert "feat: remove leader election for operator (opendatahub-io#1000)"
- we need have leader election enabled for Operator
This reverts commit 3610b0b.
- remove files (configmap) not in use
---------
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw authored Aug 6, 2024
1 parent d6ae248 commit 286caf9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,7 @@ spec:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=0.0.0.0:8080
- --leader-elect
command:
- /manager
env:
Expand Down
1 change: 1 addition & 0 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ spec:
args:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=0.0.0.0:8080"
- "--leader-elect"
8 changes: 0 additions & 8 deletions config/manager/controller_manager_config.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions config/manager/kustomization.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ resources:
generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- files:
- controller_manager_config.yaml
name: manager-config
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
Expand Down
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ spec:
- name: DEFAULT_MANIFESTS_PATH
value: /opt/manifests
args:
- --leader-elect
- --operator-name=opendatahub
image: controller:latest
imagePullPolicy: Always
Expand Down
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func init() { //nolint:gochecknoinits

func main() { //nolint:funlen
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var dscApplicationsNamespace string
var dscMonitoringNamespace string
Expand All @@ -106,6 +107,9 @@ func main() { //nolint:funlen

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&dscApplicationsNamespace, "dsc-applications-namespace", "opendatahub", "The namespace where data science cluster"+
"applications will be deployed")
flag.StringVar(&dscMonitoringNamespace, "dsc-monitoring-namespace", "opendatahub", "The namespace where data science cluster"+
Expand All @@ -119,12 +123,24 @@ func main() { //nolint:funlen

// root context
ctx := ctrl.SetupSignalHandler()

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ // single pod does not need to have LeaderElection
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "07ed84f7.opendatahub.io",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 286caf9

Please sign in to comment.