Skip to content

Commit

Permalink
feat: remove leader election for operator (opendatahub-io#1000)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
zdtsw authored May 6, 2024
1 parent 2458865 commit 3610b0b
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: opendatahub-operator-manager-config
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,6 @@ spec:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=0.0.0.0:8080
- --leader-elect
- --operator-name=opendatahub
command:
- /manager
Expand Down
1 change: 0 additions & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ spec:
args:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=0.0.0.0:8080"
- "--leader-elect"
13 changes: 0 additions & 13 deletions config/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ spec:
- name: DISABLE_DSC_CONFIG
value: 'true'
args:
- --leader-elect
- --operator-name=opendatahub
image: controller:latest
imagePullPolicy: Always
Expand Down
19 changes: 1 addition & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ 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 @@ -104,9 +103,6 @@ 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 @@ -118,24 +114,11 @@ func main() { //nolint:funlen

ctrl.SetLogger(logger.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")
Expand Down

0 comments on commit 3610b0b

Please sign in to comment.