From cc2f03c55a36830c7352ea7eee0da5908bda4105 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Mon, 6 May 2024 17:57:41 +0200 Subject: [PATCH] feat: remove leader election for operator (#1000) - since our design is for only one instance of pod, there is no need to enable leader-election - in a shady env. this can cause error Signed-off-by: Wen Zhou --- ...-operator-manager-config_v1_configmap.yaml | 13 ------------ .../rhods-operator.clusterserviceversion.yaml | 1 - config/default/manager_auth_proxy_patch.yaml | 1 - config/manager/controller_manager_config.yaml | 13 ------------ config/manager/manager.yaml | 1 - main.go | 21 ++----------------- 6 files changed, 2 insertions(+), 48 deletions(-) diff --git a/bundle/manifests/redhat-ods-operator-manager-config_v1_configmap.yaml b/bundle/manifests/redhat-ods-operator-manager-config_v1_configmap.yaml index 6328abbfeb0..be93ce5650b 100644 --- a/bundle/manifests/redhat-ods-operator-manager-config_v1_configmap.yaml +++ b/bundle/manifests/redhat-ods-operator-manager-config_v1_configmap.yaml @@ -9,19 +9,6 @@ data: bindAddress: 0.0.0.0:8080 webhook: port: 9443 - leaderElection: - leaderElect: true - resourceName: 07ed84f7.opendatahub.io - # leaderElectionReleaseOnCancel defines if the leader should step down volume - # 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 kind: ConfigMap metadata: name: redhat-ods-operator-manager-config diff --git a/bundle/manifests/rhods-operator.clusterserviceversion.yaml b/bundle/manifests/rhods-operator.clusterserviceversion.yaml index 4a35574e1fe..301732e82ed 100644 --- a/bundle/manifests/rhods-operator.clusterserviceversion.yaml +++ b/bundle/manifests/rhods-operator.clusterserviceversion.yaml @@ -1672,7 +1672,6 @@ spec: - args: - --health-probe-bind-address=:8081 - --metrics-bind-address=0.0.0.0:8080 - - --leader-elect command: - /manager image: REPLACE_IMAGE:latest diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index 348b4430479..287adcc0029 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -13,4 +13,3 @@ spec: args: - "--health-probe-bind-address=:8081" - "--metrics-bind-address=0.0.0.0:8080" - - "--leader-elect" diff --git a/config/manager/controller_manager_config.yaml b/config/manager/controller_manager_config.yaml index 29840e17aef..ec87ba2becd 100644 --- a/config/manager/controller_manager_config.yaml +++ b/config/manager/controller_manager_config.yaml @@ -6,16 +6,3 @@ metrics: bindAddress: 0.0.0.0:8080 webhook: port: 9443 -leaderElection: - leaderElect: true - resourceName: 07ed84f7.opendatahub.io -# leaderElectionReleaseOnCancel defines if the leader should step down volume -# 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 diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 1319533affb..a62c1f633c9 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -37,7 +37,6 @@ spec: - command: - /manager args: - - --leader-elect - --operator-name=opendatahub image: controller:latest imagePullPolicy: Always diff --git a/main.go b/main.go index 9e1e8d145ca..52f58be9b95 100644 --- a/main.go +++ b/main.go @@ -94,7 +94,6 @@ func init() { //nolint:gochecknoinits func main() { var metricsAddr string - var enableLeaderElection bool var probeAddr string var dscApplicationsNamespace string var dscMonitoringNamespace string @@ -103,10 +102,7 @@ func main() { 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", "redhat-ods-applications", "The namespace where data science cluster"+ + flag.StringVar(&dscApplicationsNamespace, "dsc-applications-namespace", "opendatahub", "The namespace where data science cluster"+ "applications will be deployed") flag.StringVar(&dscMonitoringNamespace, "dsc-monitoring-namespace", "redhat-ods-monitoring", "The namespace where data science cluster"+ "monitoring stack will be deployed") @@ -117,24 +113,11 @@ func main() { ctrl.SetLogger(common.ConfigLoggers(logmode)) - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ // single pod does not need to have LeaderElection 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")