From 48c95db559dca7d72231941c4e32c407406cd9f6 Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Tue, 9 Jan 2024 20:18:09 -0700 Subject: [PATCH] Only add opts cache to controller manager when a namespace is specified: We want to be able to watch all namespaces if a watchnamespace is not specified. Signed-off-by: Jacob Weinstock --- main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 9c1235da..8c469e7f 100644 --- a/main.go +++ b/main.go @@ -281,15 +281,11 @@ func main() { //nolint:funlen broadcaster := cgrecord.NewBroadcasterWithCorrelatorOptions(cgrecord.CorrelatorOptions{ BurstSize: 100, //nolint:gomnd }) - - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ + opts := ctrl.Options{ Scheme: scheme, Metrics: metricsserver.Options{ BindAddress: metricsAddr, }, - Cache: cache.Options{ - DefaultNamespaces: map[string]cache.Config{watchNamespace: {}}, - }, LeaderElection: enableLeaderElection, LeaderElectionID: "controller-leader-election-capt", LeaderElectionNamespace: leaderElectionNamespace, @@ -298,7 +294,13 @@ func main() { //nolint:funlen RetryPeriod: &leaderElectionRetryPeriod, HealthProbeBindAddress: healthAddr, EventBroadcaster: broadcaster, - }) + } + if watchNamespace != "" { + opts.Cache = cache.Options{ + DefaultNamespaces: map[string]cache.Config{watchNamespace: {}}, + } + } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts) if err != nil { setupLog.Error(err, "unable to start manager") os.Exit(1)