Skip to content

Commit

Permalink
Merge pull request #185 from vshn/flags
Browse files Browse the repository at this point in the history
Move "Leader-election" CLI flag to Env var
  • Loading branch information
ccremer authored Dec 8, 2020
2 parents ef96e11 + 621d1ca commit 32fc4b1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Configuration struct {
PodFilter string `koanf:"podfilter"`
PromURL string `koanf:"promurl"`
RestartPolicy string `koanf:"restartpolicy"`

// Enabling this will ensure there is only one active controller manager.
EnableLeaderElection bool `koanf:"enable-leader-election"`
}

var (
Expand All @@ -71,6 +74,7 @@ func NewDefaultConfig() *Configuration {
RestartPolicy: "OnFailure",
MetricsBindAddress: ":8080",
PodFilter: "backupPod=true",
EnableLeaderElection: true,
}
}

Expand Down
2 changes: 0 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ spec:
containers:
- name: k8up
image: quay.io/vshn/k8up:latest
args:
- --enable-leader-election=true
resources:
limits:
cpu: 300m
Expand Down
9 changes: 1 addition & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"flag"
"os"
"strings"

Expand Down Expand Up @@ -47,12 +46,6 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

var enableLeaderElection bool
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Parse()

loadEnvironmentVariables()

executor.GetExecutor()
Expand All @@ -61,7 +54,7 @@ func main() {
Scheme: scheme,
MetricsBindAddress: cfg.Config.MetricsBindAddress,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElection: cfg.Config.EnableLeaderElection,
LeaderElectionID: "d2ab61da.syn.tools",
})
if err != nil {
Expand Down

0 comments on commit 32fc4b1

Please sign in to comment.