{"record":{"id":"da9388cb4cbe1115","repo":"quarkusio/quarkus","slug":"failed-to-read-kubeconfig-file-kubeconfigpath","errorCode":null,"errorMessage":"Failed to read kubeconfig file: \" + kubeconfigPath","messagePattern":"Failed to read kubeconfig file: \" \\+ kubeconfigPath","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"extensions/kubernetes-client/runtime-internal/src/main/java/io/quarkus/kubernetes/client/runtime/internal/KubernetesClientUtils.java","lineNumber":31,"sourceCode":"\npublic class KubernetesClientUtils {\n\n    private static final String PREFIX = \"quarkus.kubernetes-client.\";\n\n    private KubernetesClientUtils() {\n    }\n\n    public static Config createConfig(KubernetesClientConfig clientConfig) {\n        io.smallrye.config.Config config = io.smallrye.config.Config.get();\n        boolean globalTrustAll = config.getOptionalValue(\"quarkus.tls.trust-all\", Boolean.class).orElse(false);\n        Config base;\n        if (clientConfig.kubeconfigFile().isPresent()) {\n            String kubeconfigPath = clientConfig.kubeconfigFile().get();\n            try {\n                String kubeconfig = Files.readString(Path.of(kubeconfigPath));\n                base = Config.fromKubeconfig(kubeconfig);\n            } catch (IOException e) {\n                throw new RuntimeException(\"Failed to read kubeconfig file: \" + kubeconfigPath, e);\n            }\n        } else {\n            base = Config.autoConfigure(null);\n        }\n        boolean trustAll = clientConfig.trustCerts().isPresent() ? clientConfig.trustCerts().get() : globalTrustAll;\n        final var configBuilder = new ConfigBuilder(base).withTrustCerts(trustAll);\n        clientConfig.watchReconnectInterval().ifPresent(d -> configBuilder.withWatchReconnectInterval(millisAsInt(d)));\n        clientConfig.watchReconnectLimit().ifPresent(configBuilder::withWatchReconnectLimit);\n        clientConfig.connectionTimeout().ifPresent(d -> configBuilder.withConnectionTimeout(millisAsInt(d)));\n        clientConfig.requestTimeout().ifPresent(d -> configBuilder.withRequestTimeout(millisAsInt(d)));\n        clientConfig.apiServerUrl().ifPresent(configBuilder::withMasterUrl);\n        clientConfig.namespace().ifPresent(configBuilder::withNamespace);\n        clientConfig.username().ifPresent(configBuilder::withUsername);\n        clientConfig.password().ifPresent(configBuilder::withPassword);\n        clientConfig.token().ifPresent(configBuilder::withOauthToken);\n        clientConfig.caCertFile().ifPresent(configBuilder::withCaCertFile);\n        clientConfig.caCertData().ifPresent(configBuilder::withCaCertData);\n        clientConfig.clientCertFile().ifPresent(configBuilder::withClientCertFile);","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/kubernetes-client/runtime-internal/src/main/java/io/quarkus/kubernetes/client/runtime/internal/KubernetesClientUtils.java#L13-L49","documentation":"KubernetesClientUtils.createConfig builds the Kubernetes client Config. When a kubeconfig file is explicitly configured (clientConfig.kubeconfigFile()), the file must be readable; any IOException reading it aborts client creation with this RuntimeException wrapping the path.","triggerScenarios":"quarkus.kubernetes-client.kubeconfig-file (via clientConfig.kubeconfigFile()) points to a file that does not exist, is a directory, or is unreadable; createConfig is invoked by createClient when building the client.","commonSituations":"Typo or wrong absolute path in kubeconfig-file config; file generated at runtime but not yet present; CI container lacking the mounted kubeconfig; permission issues after copying credentials.","solutions":["Fix the configured path to an existing, readable kubeconfig file (ls -l <path> to verify).","Ensure the file is mounted/copied into CI containers and readable by the build user.","Remove the kubeconfig-file property to fall back to Config.autoConfigure (default ~/.kube/config / in-cluster config)."],"exampleFix":"// before\nquarkus.kubernetes-client.kubeconfig-file=/home/ci/.kube/nonexistent-config\n// after\nquarkus.kubernetes-client.kubeconfig-file=/home/ci/.kube/config","handlingStrategy":"validation","validationCode":"// Verify kubeconfig readability before creating the client\nString kubeconfigFile = clientConfig.kubeconfigFile().orElse(null);\nif (kubeconfigFile != null) {\n    Path p = Path.of(kubeconfigFile);\n    if (!Files.isRegularFile(p) || !Files.isReadable(p)) {\n        throw new IllegalStateException(\"kubeconfig file missing or unreadable: \" + kubeconfigFile);\n    }\n    Config.fromKubeconfig(Files.readString(p)); // fail fast on malformed YAML too\n}","typeGuard":null,"tryCatchPattern":"try {\n    client = KubernetesClientUtils.createClient(clientConfig);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Failed to read kubeconfig file:\")) {\n        LOGGER.errorf(\"Fix quarkus.kubernetes-client.kubeconfig-file: %s\", e.getMessage());\n        // fallback to auto-configured (in-cluster) credentials\n        client = new KubernetesClientBuilder().build();\n    } else { throw e; }\n}","preventionTips":["Mount the kubeconfig (or use in-cluster ServiceAccount) in build/test containers.","Validate the path exists with a preflight check in CI scripts.","Prefer Config.autoConfigure / in-cluster auth over explicit kubeconfig paths when possible."],"tags":["kubernetes","kubeconfig","file-io","configuration"],"backgroundTag":"kubeconfig-file-unreadable","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}