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 51c6540
Showing 1 changed file with 3 additions and 10 deletions.
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 51c6540

Please sign in to comment.