From dde262fc00d7d8d48190971ec71149d29c881cb1 Mon Sep 17 00:00:00 2001 From: Paulin Todev Date: Mon, 19 Feb 2024 15:12:42 +0000 Subject: [PATCH] Add a namespace allowlist to loki.source.podlogs --- component/loki/source/podlogs/controller.go | 15 +++++++++++++-- component/loki/source/podlogs/podlogs.go | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/component/loki/source/podlogs/controller.go b/component/loki/source/podlogs/controller.go index 5aa86d0391a9..f6fa749c5860 100644 --- a/component/loki/source/podlogs/controller.go +++ b/component/loki/source/podlogs/controller.go @@ -47,7 +47,7 @@ func newController(l log.Logger, reconciler *reconciler) *controller { } } -func (ctrl *controller) UpdateConfig(cfg *rest.Config) error { +func (ctrl *controller) UpdateConfig(cfg *rest.Config, namespaces []string) error { scheme := runtime.NewScheme() for _, add := range []func(*runtime.Scheme) error{ corev1.AddToScheme, @@ -58,7 +58,18 @@ func (ctrl *controller) UpdateConfig(cfg *rest.Config) error { } } - cache, err := cache.New(cfg, cache.Options{Scheme: scheme}) + defaultNamespaces := map[string]cache.Config{} + for _, ns := range namespaces { + defaultNamespaces[ns] = cache.Config{} + } + + cache, err := cache.New( + cfg, + cache.Options{ + Scheme: scheme, + DefaultNamespaces: defaultNamespaces, + }, + ) if err != nil { return err } diff --git a/component/loki/source/podlogs/podlogs.go b/component/loki/source/podlogs/podlogs.go index f7a194e4b79a..ccdfbe93df83 100644 --- a/component/loki/source/podlogs/podlogs.go +++ b/component/loki/source/podlogs/podlogs.go @@ -43,6 +43,8 @@ type Arguments struct { // Client settings to connect to Kubernetes. Client commonk8s.ClientArguments `river:"client,block,optional"` + Namespaces []string `river:"namespaces,attr,optional"` + Selector config.LabelSelector `river:"selector,block,optional"` NamespaceSelector config.LabelSelector `river:"namespace_selector,block,optional"` @@ -296,7 +298,7 @@ func (c *Component) updateController(args Arguments) error { } c.restConfig = cfg - return c.controller.UpdateConfig(cfg) + return c.controller.UpdateConfig(cfg, args.Namespaces) } // DebugInfo returns debug information for loki.source.podlogs.