From 2da3ffefc0780a80289f7aa944840a7b14e54070 Mon Sep 17 00:00:00 2001 From: Paschalis Tsilias Date: Tue, 10 Oct 2023 17:33:05 +0300 Subject: [PATCH] operator: initialise default namespaces map config (#5424) (#5426) (cherry picked from commit 37c40cc530c101d993f063d1825f384738531bcd) Co-authored-by: William Dumont --- component/loki/source/kubernetes_events/event_controller.go | 4 +++- component/prometheus/operator/common/crdmanager.go | 2 ++ pkg/operator/operator.go | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/component/loki/source/kubernetes_events/event_controller.go b/component/loki/source/kubernetes_events/event_controller.go index d6ddd8d41833..c161f01a288f 100644 --- a/component/loki/source/kubernetes_events/event_controller.go +++ b/component/loki/source/kubernetes_events/event_controller.go @@ -97,7 +97,9 @@ func (ctrl *eventController) runError(ctx context.Context) error { } defaultNamespaces := map[string]cache.Config{} - defaultNamespaces[ctrl.task.Namespace] = cache.Config{} + if ctrl.task.Namespace != "" { + defaultNamespaces[ctrl.task.Namespace] = cache.Config{} + } opts := cache.Options{ Scheme: scheme, DefaultNamespaces: defaultNamespaces, diff --git a/component/prometheus/operator/common/crdmanager.go b/component/prometheus/operator/common/crdmanager.go index 7ce1aa368827..fe75e5714b47 100644 --- a/component/prometheus/operator/common/crdmanager.go +++ b/component/prometheus/operator/common/crdmanager.go @@ -243,6 +243,8 @@ func (c *crdManager) runInformers(restConfig *rest.Config, ctx context.Context) return fmt.Errorf("building label selector: %w", err) } for _, ns := range c.args.Namespaces { + // TODO: This is going down an unnecessary extra step in the cache when `c.args.Namespaces` defaults to NamespaceAll. + // This code path should be simplified and support a scenario when len(c.args.Namespace) == 0. defaultNamespaces := map[string]cache.Config{} defaultNamespaces[ns] = cache.Config{} opts := cache.Options{ diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index c1c08862473d..adad79288ec7 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -87,7 +87,10 @@ func (c *Config) registerFlags(f *flag.FlagSet) error { c.Controller.WebhookServer = webhook.NewServer(webhookServerOptions) - c.Controller.Cache.DefaultNamespaces[namespace] = cache.Config{} + if namespace != "" { + c.Controller.Cache.DefaultNamespaces = map[string]cache.Config{} + c.Controller.Cache.DefaultNamespaces[namespace] = cache.Config{} + } // Custom initial values for the endpoint names. c.Controller.ReadinessEndpointName = "/-/ready"