Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit 6389f2f

Browse files
committed
Add a config flag to allow not listwatching namespaces
The namespaces cache will be an empty store in this case. Down the line all of the code _should_ just work for instance emitting an error log if you try to access namespace labels.
1 parent 8dfd2a0 commit 6389f2f

1 file changed

Lines changed: 32 additions & 19 deletions

File tree

  • src/sources/kubernetes_logs

src/sources/kubernetes_logs/mod.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ pub struct Config {
107107
))]
108108
extra_namespace_label_selector: String,
109109

110+
/// Specifies whether or not to enrich with namespace fields.
111+
///
112+
/// This can be useful to make Vector not pull in namespaces to reduce load on
113+
/// kube-apiserver and daemonset memory usage in clusters with lots of namespaces.
114+
///
115+
add_namespace_fields: bool,
116+
110117
/// The name of the Kubernetes [Node][node] that is running.
111118
///
112119
/// Configured to use an environment variable by default, to be evaluated to a value provided by
@@ -290,6 +297,7 @@ impl Default for Config {
290297
Self {
291298
extra_label_selector: "".to_string(),
292299
extra_namespace_label_selector: "".to_string(),
300+
add_namespace_fields: true,
293301
self_node_name: default_self_node_name_env_template(),
294302
extra_field_selector: "".to_string(),
295303
auto_partial_merge: true,
@@ -555,6 +563,7 @@ struct Source {
555563
field_selector: String,
556564
label_selector: String,
557565
namespace_label_selector: String,
566+
add_namespace_fields: bool,
558567
node_selector: String,
559568
self_node_name: String,
560569
include_paths: Vec<glob::Pattern>,
@@ -643,6 +652,7 @@ impl Source {
643652
field_selector,
644653
label_selector,
645654
namespace_label_selector,
655+
add_namespace_fields: config.add_namespace_fields,
646656
node_selector,
647657
self_node_name,
648658
include_paths,
@@ -679,6 +689,7 @@ impl Source {
679689
field_selector,
680690
label_selector,
681691
namespace_label_selector,
692+
add_namespace_fields,
682693
node_selector,
683694
self_node_name,
684695
include_paths,
@@ -733,27 +744,29 @@ impl Source {
733744

734745
// -----------------------------------------------------------------
735746

736-
let namespaces = Api::<Namespace>::all(client.clone());
737-
let ns_watcher = watcher(
738-
namespaces,
739-
watcher::Config {
740-
label_selector: Some(namespace_label_selector),
741-
list_semantic: list_semantic.clone(),
742-
page_size: get_page_size(use_apiserver_cache),
743-
..Default::default()
744-
},
745-
)
746-
.backoff(watcher::DefaultBackoff::default());
747747
let ns_store_w = reflector::store::Writer::default();
748748
let ns_state = ns_store_w.as_reader();
749-
let ns_cacher = MetaCache::new();
750-
751-
reflectors.push(tokio::spawn(custom_reflector(
752-
ns_store_w,
753-
ns_cacher,
754-
ns_watcher,
755-
delay_deletion,
756-
)));
749+
if add_namespace_fields {
750+
let namespaces = Api::<Namespace>::all(client.clone());
751+
let ns_watcher = watcher(
752+
namespaces,
753+
watcher::Config {
754+
label_selector: Some(namespace_label_selector),
755+
list_semantic: list_semantic.clone(),
756+
page_size: get_page_size(use_apiserver_cache),
757+
..Default::default()
758+
},
759+
)
760+
.backoff(watcher::DefaultBackoff::default());
761+
let ns_cacher = MetaCache::new();
762+
763+
reflectors.push(tokio::spawn(custom_reflector(
764+
ns_store_w,
765+
ns_cacher,
766+
ns_watcher,
767+
delay_deletion,
768+
)));
769+
}
757770

758771
// -----------------------------------------------------------------
759772

0 commit comments

Comments
 (0)