From 0a7ce2e2c515037d064ce04ac28129ffec906bc0 Mon Sep 17 00:00:00 2001 From: Manjunath Kumatagi Date: Wed, 8 Dec 2021 10:33:45 +0530 Subject: [PATCH] Watch Namespace (#454) --- main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.go b/main.go index 97ce9a15e..41007651e 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,8 @@ import ( ) var ( + watchNamespace string + scheme = runtime.NewScheme() setupLog = ctrl.Log.WithName("setup") ) @@ -55,9 +57,20 @@ func main() { flag.BoolVar(&enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") + flag.StringVar( + &watchNamespace, + "namespace", + "", + "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.", + ) flag.Parse() ctrl.SetLogger(zap.New(zap.UseDevMode(true))) + + if watchNamespace != "" { + setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace) + } + syncPeriod := 15 * time.Second mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, @@ -66,6 +79,7 @@ func main() { LeaderElection: enableLeaderElection, LeaderElectionID: "effcf9b8.cluster.x-k8s.io", SyncPeriod: &syncPeriod, + Namespace: watchNamespace, }) if err != nil { setupLog.Error(err, "unable to start manager")