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

Commit d5b63e0

Browse files
authored
Merge pull request #181 from cpanato/add-watch-namespace
✨ manager: add option to watch a specific namespace for reconciliation
2 parents 9039fa7 + 8dab9c6 commit d5b63e0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func main() {
5858
metricsAddr string
5959
webhookPort int
6060
syncPeriod time.Duration
61+
watchNamespace string
6162
)
6263

6364
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
@@ -85,6 +86,13 @@ func main() {
8586
"The minimum interval at which watched resources are reconciled (e.g. 15m)",
8687
)
8788

89+
flag.StringVar(
90+
&watchNamespace,
91+
"namespace",
92+
"",
93+
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.",
94+
)
95+
8896
flag.IntVar(&webhookPort,
8997
"webhook-port",
9098
0,
@@ -95,6 +103,10 @@ func main() {
95103

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

106+
if watchNamespace != "" {
107+
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace)
108+
}
109+
98110
// Machine and cluster operations can create enough events to trigger the event recorder spam filter
99111
// Setting the burst size higher ensures all events will be recorded and submitted to the API
100112
broadcaster := record.NewBroadcasterWithCorrelatorOptions(record.CorrelatorOptions{
@@ -109,6 +121,7 @@ func main() {
109121
LeaderElection: enableLeaderElection,
110122
LeaderElectionID: "controller-leader-election-capp",
111123
LeaderElectionNamespace: leaderElectionNamespace,
124+
Namespace: watchNamespace,
112125
SyncPeriod: &syncPeriod,
113126
HealthProbeBindAddress: healthAddr,
114127
})

0 commit comments

Comments
 (0)