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

Commit dc230ad

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 9daa00c commit dc230ad

File tree

1 file changed

+32
-19
lines changed
  • src/sources/kubernetes_logs

1 file changed

+32
-19
lines changed

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
@@ -280,6 +287,7 @@ impl Default for Config {
280287
Self {
281288
extra_label_selector: "".to_string(),
282289
extra_namespace_label_selector: "".to_string(),
290+
add_namespace_fields: true,
283291
self_node_name: default_self_node_name_env_template(),
284292
extra_field_selector: "".to_string(),
285293
auto_partial_merge: true,
@@ -544,6 +552,7 @@ struct Source {
544552
field_selector: String,
545553
label_selector: String,
546554
namespace_label_selector: String,
555+
add_namespace_fields: bool,
547556
node_selector: String,
548557
self_node_name: String,
549558
include_paths: Vec<glob::Pattern>,
@@ -632,6 +641,7 @@ impl Source {
632641
field_selector,
633642
label_selector,
634643
namespace_label_selector,
644+
add_namespace_fields: config.add_namespace_fields,
635645
node_selector,
636646
self_node_name,
637647
include_paths,
@@ -667,6 +677,7 @@ impl Source {
667677
field_selector,
668678
label_selector,
669679
namespace_label_selector,
680+
add_namespace_fields,
670681
node_selector,
671682
self_node_name,
672683
include_paths,
@@ -720,27 +731,29 @@ impl Source {
720731

721732
// -----------------------------------------------------------------
722733

723-
let namespaces = Api::<Namespace>::all(client.clone());
724-
let ns_watcher = watcher(
725-
namespaces,
726-
watcher::Config {
727-
label_selector: Some(namespace_label_selector),
728-
list_semantic: list_semantic.clone(),
729-
page_size: get_page_size(use_apiserver_cache),
730-
..Default::default()
731-
},
732-
)
733-
.backoff(watcher::DefaultBackoff::default());
734734
let ns_store_w = reflector::store::Writer::default();
735735
let ns_state = ns_store_w.as_reader();
736-
let ns_cacher = MetaCache::new();
737-
738-
reflectors.push(tokio::spawn(custom_reflector(
739-
ns_store_w,
740-
ns_cacher,
741-
ns_watcher,
742-
delay_deletion,
743-
)));
736+
if add_namespace_fields {
737+
let namespaces = Api::<Namespace>::all(client.clone());
738+
let ns_watcher = watcher(
739+
namespaces,
740+
watcher::Config {
741+
label_selector: Some(namespace_label_selector),
742+
list_semantic: list_semantic.clone(),
743+
page_size: get_page_size(use_apiserver_cache),
744+
..Default::default()
745+
},
746+
)
747+
.backoff(watcher::DefaultBackoff::default());
748+
let ns_cacher = MetaCache::new();
749+
750+
reflectors.push(tokio::spawn(custom_reflector(
751+
ns_store_w,
752+
ns_cacher,
753+
ns_watcher,
754+
delay_deletion,
755+
)));
756+
}
744757

745758
// -----------------------------------------------------------------
746759

0 commit comments

Comments
 (0)