From: aravind.est Date: Wed, 10 Dec 2025 18:54:06 +0000 (+0000) Subject: fix: prioritize filesystem kubeconfig over classpath in KubernetesConfig X-Git-Tag: 0.3.0~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=81380f8037a90fab86d8dcf9d0fce65fac94a41d;p=smo%2Fteiv.git fix: prioritize filesystem kubeconfig over classpath in KubernetesConfig Check filesystem first before falling back to classpath resources. Issue-ID: SMO-208 Change-Id: Ide0b6e2c9a2646a3f814bb25ffa4e178bf9b8cce Signed-off-by: aravind.est --- diff --git a/adapters/focom-to-teiv-adapter/src/main/java/org/oran/smo/teiv/adapters/focom_to_teiv_adapter/KubernetesConfig.java b/adapters/focom-to-teiv-adapter/src/main/java/org/oran/smo/teiv/adapters/focom_to_teiv_adapter/KubernetesConfig.java index f7cd5d0..662eefa 100644 --- a/adapters/focom-to-teiv-adapter/src/main/java/org/oran/smo/teiv/adapters/focom_to_teiv_adapter/KubernetesConfig.java +++ b/adapters/focom-to-teiv-adapter/src/main/java/org/oran/smo/teiv/adapters/focom_to_teiv_adapter/KubernetesConfig.java @@ -30,6 +30,9 @@ import org.springframework.context.annotation.Configuration; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; @Slf4j @Configuration @@ -58,12 +61,22 @@ public class KubernetesConfig { if (path != null && !path.isBlank()) { log.debug("Using explicit kubeconfig from path: {}", path); - InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path); + String kubeconfig; - if (inputStream == null) { - throw new IOException("Kubeconfig file not found in classpath: " + path); + // Check filesystem first + Path filePath = Paths.get(path); + if (Files.exists(filePath)) { + log.debug("Loading kubeconfig from filesystem: {}", path); + kubeconfig = Files.readString(filePath, StandardCharsets.UTF_8); + } else { + // Fall back to classpath + log.debug("Loading kubeconfig from classpath: {}", path); + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path); + if (inputStream == null) { + throw new IOException("Kubeconfig file not found in filesystem or classpath: " + path); + } + kubeconfig = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); } - String kubeconfig = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); config = Config.fromKubeconfig(kubeconfig); } else { log.info("No kubeconfig path provided. Using default auto-configured Kubernetes client");