Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 28df953

Browse files
authored
Merge pull request #180 from cpanato/leaderelection-namespace
✨ manager: add leader election namespace option
2 parents 21b3b58 + 42cf409 commit 28df953

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

main.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,24 @@ func init() {
5151
func main() {
5252

5353
var (
54-
enableLeaderElection bool
55-
healthAddr string
56-
metricsAddr string
57-
webhookPort int
54+
enableLeaderElection bool
55+
leaderElectionNamespace string
56+
healthAddr string
57+
metricsAddr string
58+
webhookPort int
5859
)
5960

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

65+
flag.StringVar(
66+
&leaderElectionNamespace,
67+
"leader-election-namespace",
68+
"",
69+
"Namespace that the controller performs leader election in. If unspecified, the controller will discover which namespace it is running in.",
70+
)
71+
6472
flag.StringVar(&healthAddr,
6573
"health-addr",
6674
":9440",
@@ -86,13 +94,14 @@ func main() {
8694
})
8795

8896
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
89-
Scheme: scheme,
90-
MetricsBindAddress: metricsAddr,
91-
Port: webhookPort,
92-
EventBroadcaster: broadcaster,
93-
LeaderElection: enableLeaderElection,
94-
LeaderElectionID: "cad3ba79.cluster.x-k8s.io",
95-
HealthProbeBindAddress: healthAddr,
97+
Scheme: scheme,
98+
MetricsBindAddress: metricsAddr,
99+
Port: webhookPort,
100+
EventBroadcaster: broadcaster,
101+
LeaderElection: enableLeaderElection,
102+
LeaderElectionID: "controller-leader-election-capp",
103+
LeaderElectionNamespace: leaderElectionNamespace,
104+
HealthProbeBindAddress: healthAddr,
96105
})
97106
if err != nil {
98107
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)