From b24fff57211840d7d9098e1993883d7d9e81211b Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 29 Sep 2023 20:16:26 -0600 Subject: [PATCH] Create a manager cache only when a ns is specified: A cache with a "" namespace causes reconcile errors: "unable to get: namespace/machine because of unknown namespace for the cache" With this change is the ns is "" we use the default behavior of the manager which is to watch and list all namespaces. Signed-off-by: Jacob Weinstock --- main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 4ba620e..ea8b125 100644 --- a/main.go +++ b/main.go @@ -116,18 +116,23 @@ func main() { setupLog.Info("Watching objects in namespace for reconciliation", "namespace", kubeNamespace) - mgr, err := ctrl.NewManager(cfg, ctrl.Options{ + opts := ctrl.Options{ Scheme: scheme, - Cache: cache.Options{ - DefaultNamespaces: map[string]cache.Config{kubeNamespace: {}}, - }, Metrics: metricsserver.Options{ BindAddress: metricsAddr, }, HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "e74dec1a.tinkerbell.org", - }) + } + // If a namespace is specified, only watch that namespace. Otherwise, watch all namespaces. + if kubeNamespace != "" { + opts.Cache = cache.Options{ + DefaultNamespaces: map[string]cache.Config{kubeNamespace: {}}, + } + } + + mgr, err := ctrl.NewManager(cfg, opts) if err != nil { setupLog.Error(err, "unable to start manager") os.Exit(1)