Skip to content

Commit 460b8bd

Browse files
committed
manager: add option to configure the leader election namespace
1 parent a86fec3 commit 460b8bd

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

main.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func init() {
7373
var (
7474
metricsAddr string
7575
enableLeaderElection bool
76+
leaderElectionNamespace string
7677
watchNamespace string
7778
profilerAddress string
7879
azureClusterConcurrency int
@@ -99,6 +100,13 @@ func InitFlags(fs *pflag.FlagSet) {
99100
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.",
100101
)
101102

103+
flag.StringVar(
104+
&leaderElectionNamespace,
105+
"leader-election-namespace",
106+
"",
107+
"Namespace that the controller performs leader election in. If unspecified, the controller will discover which namespace it is running in.",
108+
)
109+
102110
fs.StringVar(
103111
&watchNamespace,
104112
"namespace",
@@ -182,15 +190,16 @@ func main() {
182190
})
183191

184192
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
185-
Scheme: scheme,
186-
MetricsBindAddress: metricsAddr,
187-
LeaderElection: enableLeaderElection,
188-
LeaderElectionID: "controller-leader-election-capz",
189-
SyncPeriod: &syncPeriod,
190-
Namespace: watchNamespace,
191-
HealthProbeBindAddress: healthAddr,
192-
Port: webhookPort,
193-
EventBroadcaster: broadcaster,
193+
Scheme: scheme,
194+
MetricsBindAddress: metricsAddr,
195+
LeaderElection: enableLeaderElection,
196+
LeaderElectionID: "controller-leader-election-capz",
197+
LeaderElectionNamespace: leaderElectionNamespace,
198+
SyncPeriod: &syncPeriod,
199+
Namespace: watchNamespace,
200+
HealthProbeBindAddress: healthAddr,
201+
Port: webhookPort,
202+
EventBroadcaster: broadcaster,
194203
})
195204
if err != nil {
196205
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)