Skip to content

Commit 0a7ce2e

Browse files
authored
Watch Namespace (#454)
1 parent 6b14e4b commit 0a7ce2e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import (
3535
)
3636

3737
var (
38+
watchNamespace string
39+
3840
scheme = runtime.NewScheme()
3941
setupLog = ctrl.Log.WithName("setup")
4042
)
@@ -55,9 +57,20 @@ func main() {
5557
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
5658
"Enable leader election for controller manager. "+
5759
"Enabling this will ensure there is only one active controller manager.")
60+
flag.StringVar(
61+
&watchNamespace,
62+
"namespace",
63+
"",
64+
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.",
65+
)
5866
flag.Parse()
5967

6068
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
69+
70+
if watchNamespace != "" {
71+
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace)
72+
}
73+
6174
syncPeriod := 15 * time.Second
6275
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
6376
Scheme: scheme,
@@ -66,6 +79,7 @@ func main() {
6679
LeaderElection: enableLeaderElection,
6780
LeaderElectionID: "effcf9b8.cluster.x-k8s.io",
6881
SyncPeriod: &syncPeriod,
82+
Namespace: watchNamespace,
6983
})
7084
if err != nil {
7185
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)