Skip to content

Commit

Permalink
fix(operator): move to use leader election by lease
Browse files Browse the repository at this point in the history
Fixes #711

Signed-off-by: Aslak Knutsen <aslak@4fs.no>
  • Loading branch information
aslakknutsen committed Feb 23, 2021
1 parent 76eaf19 commit 2582755
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resources:
- role.yaml
- role_binding.yaml
#- leader_election_role.yaml
#- leader_election_role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
Expand Down
2 changes: 1 addition & 1 deletion config/rbac/leader_election_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ roleRef:
name: leader-election-role
subjects:
- kind: ServiceAccount
name: default
name: istio-workspace
namespace: system
13 changes: 3 additions & 10 deletions pkg/cmd/serve/cmd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package serve

import (
"context"
"fmt"
"os"
"strings"

"github.com/go-logr/logr"
"github.com/operator-framework/operator-lib/leader"

"github.com/maistra/istio-workspace/api"
"github.com/maistra/istio-workspace/controllers"
Expand Down Expand Up @@ -63,18 +61,13 @@ func startOperator(cmd *cobra.Command, args []string) error {
return err
}

ctx := context.Background()

// Become the leader before proceeding
if e := leader.Become(ctx, "istio-workspace-lock"); e != nil {
logger().Error(e, "")
return e
}

managerOptions := manager.Options{
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
HealthProbeBindAddress: "0.0.0.0:8282",
LeaderElection: true,
LeaderElectionID: "istio-workspace-lock",
}

if len(namespaces) == 1 {
managerOptions.Namespace = namespaces[0]
} else {
Expand Down

0 comments on commit 2582755

Please sign in to comment.