Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use leader-with-lease based election in the operator #3299

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"runtime"

configv1 "github.com/openshift/api/config/v1"
"github.com/operator-framework/operator-lib/leader"
"github.com/submariner-io/admiral/pkg/log/kzerolog"
"github.com/submariner-io/admiral/pkg/names"
admversion "github.com/submariner-io/admiral/pkg/version"
Expand Down Expand Up @@ -84,8 +83,7 @@ func main() {
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&pprofAddr, "pprof-bind-address", ":8082", "The address the profiling 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.")
"Enable leader election for the controller manager to ensure there is only one active instance.")

kzerolog.AddFlags(nil)
flag.Parse()
Expand Down Expand Up @@ -121,13 +119,6 @@ func main() {

ctx := ctrl.SetupSignalHandler()

// Become the leader before proceeding
err = leader.Become(ctx, "submariner-operator-lock")
if err != nil {
log.Error(err, "")
os.Exit(1)
}

// Set up the CRDs we need
crdUpdater, err := crd.UpdaterFromRestConfig(cfg)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ spec:
image: controller:0.0.0
command:
- submariner-operator
# args:
# - --enable-leader-election
args:
- --leader-elect
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
Expand Down
11 changes: 11 additions & 0 deletions config/rbac/submariner-operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,14 @@ rules:
- servicediscoveries/finalizers
verbs:
- update
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- delete
35 changes: 23 additions & 12 deletions pkg/embeddedyamls/yamls.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: brokers.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -105,7 +105,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: submariners.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1118,7 +1118,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: servicediscoveries.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1277,7 +1277,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: clusters.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1348,7 +1348,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: endpoints.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1429,7 +1429,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: gateways.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1602,7 +1602,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: clusterglobalegressips.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1728,7 +1728,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: globalegressips.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -1903,7 +1903,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: globalingressips.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -2056,7 +2056,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: gatewayroutes.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -2117,7 +2117,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: nongatewayroutes.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -2178,7 +2178,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: routeagents.submariner.io
spec:
group: submariner.io
Expand Down Expand Up @@ -2808,6 +2808,17 @@ rules:
- servicediscoveries/finalizers
verbs:
- update
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- delete
`
Config_rbac_submariner_operator_role_binding_yaml = `---
kind: RoleBinding
Expand Down
Loading