From a4951d9125b12ab9990723507bbc3f459d3bcce4 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Thu, 16 May 2024 20:35:09 +0200 Subject: [PATCH] fix(k8s): don't trigger if scan config is set but env vars are not --- src/modules/kubernetes.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index 09a4cef40019..c0838a3ef416 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -107,7 +107,8 @@ pub fn module<'a>(context: &'a Context) -> Option> { return None; }; - let have_env_vars = context.detect_env_vars(&config.detect_env_vars); + let have_env_config = !config.detect_env_vars.is_empty(); + let have_env_vars = have_env_config.then(|| context.detect_env_vars(&config.detect_env_vars)); // If we have some config for doing the directory scan then we use it but if we don't then we // assume we should treat it like the module is enabled to preserve backward compatibility. @@ -129,7 +130,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { }) }); - if !is_kube_project.unwrap_or(true) && !have_env_vars { + if !is_kube_project.or(have_env_vars).unwrap_or(true) { return None; } @@ -445,6 +446,16 @@ users: [] }) .collect(); + let actual_none = ModuleRenderer::new("kubernetes") + .path(empty_dir.path()) + .env("KUBECONFIG", filename.to_string_lossy().as_ref()) + .config(toml::toml! { + [kubernetes] + disabled = false + detect_files = ["k8s.ext"] + }) + .collect(); + let expected = Some(format!( "{} in ", Color::Cyan.bold().paint("☸ test_context") @@ -454,6 +465,7 @@ users: [] assert_eq!(expected, actual_ext); assert_eq!(expected, actual_dir); assert_eq!(expected, actual_env_var); + assert_eq!(None, actual_none); dir.close() }