fix: prioritize filesystem kubeconfig over classpath in KubernetesConfig 57/15357/1
authoraravind.est <aravindhan.a@est.tech>
Wed, 10 Dec 2025 18:54:06 +0000 (18:54 +0000)
committeraravind.est <aravindhan.a@est.tech>
Wed, 10 Dec 2025 18:54:55 +0000 (18:54 +0000)
Check filesystem first before falling back to classpath resources.

Issue-ID: SMO-208
Change-Id: Ide0b6e2c9a2646a3f814bb25ffa4e178bf9b8cce
Signed-off-by: aravind.est <aravindhan.a@est.tech>
adapters/focom-to-teiv-adapter/src/main/java/org/oran/smo/teiv/adapters/focom_to_teiv_adapter/KubernetesConfig.java

index f7cd5d0..662eefa 100644 (file)
@@ -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");