@@ -23,7 +23,6 @@ import (
2323
2424 "github.com/operator-framework/operator-sdk/pkg/k8sutil"
2525 kubemetrics "github.com/operator-framework/operator-sdk/pkg/kube-metrics"
26- "github.com/operator-framework/operator-sdk/pkg/leader"
2726 "github.com/operator-framework/operator-sdk/pkg/log/zap"
2827 "github.com/operator-framework/operator-sdk/pkg/metrics"
2928 sdkVersion "github.com/operator-framework/operator-sdk/version"
@@ -53,6 +52,13 @@ func init() {
5352 "t" ,
5453 map [string ]string {},
5554 "Tags to add to the aws instances on which the cluster nodes run on" )
55+
56+ pflag .StringVarP (
57+ & flags .LeaderElectionNamespace ,
58+ "leader-election-namespace" ,
59+ "l" ,
60+ "" ,
61+ "The leader election namespace. Will auto-discover if not provided" )
5662}
5763
5864func printVersion () {
@@ -106,17 +112,16 @@ func main() {
106112 os .Exit (1 )
107113 }
108114
109- ctx := context .TODO ()
110- // Become the leader before proceeding
111- err = leader .Become (ctx , "node-tagger-lock" )
112- if err != nil {
113- log .Error (err , "" )
114- os .Exit (1 )
115- }
116115
117116 managerOptions := manager.Options {
118117 MetricsBindAddress : fmt .Sprintf ("%s:%d" , metricsHost , metricsPort ),
119118 HealthProbeBindAddress : fmt .Sprintf ("%s:%d" , healthProbeHost , healthProbePort ),
119+ LeaderElection : true ,
120+ LeaderElectionID : "node-tagger-lock" ,
121+ }
122+
123+ if flags .LeaderElectionNamespace != "" {
124+ managerOptions .LeaderElectionNamespace = flags .LeaderElectionNamespace
120125 }
121126
122127 // Create a new Cmd to provide shared dependencies and start components
@@ -155,7 +160,7 @@ func main() {
155160 if err != nil {
156161 log .Error (err , "Error getting service Monitor namespace" )
157162 } else {
158- addMetrics (ctx , cfg , serviceMonitorNamespace )
163+ addMetrics (context . TODO () , cfg , serviceMonitorNamespace )
159164 }
160165
161166 log .Info ("Starting the Cmd." )
0 commit comments