{"record":{"id":"97cd2271e555d415","repo":"apache/dolphinscheduler","slug":"fail-to-build-k8s-apiclient","errorCode":null,"errorMessage":"fail to build k8s ApiClient","messagePattern":"fail to build k8s ApiClient","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"critical","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java","lineNumber":112,"sourceCode":"                }\n            }\n            return client.pods().inNamespace(namespace)\n                    .withName(podName)\n                    .tailingLines(LOG_LINES)\n                    .getLog(Boolean.TRUE);\n        } catch (Exception e) {\n            log.error(\"fail to getPodLog\", e);\n            log.error(\"response bodies : {}\", e.getMessage());\n        }\n        return null;\n    }\n\n    public void buildClient(String configYaml) {\n        try {\n            Config config = Config.fromKubeconfig(configYaml);\n            client = new KubernetesClientBuilder().withConfig(config).build();\n        } catch (Exception e) {\n            throw new TaskException(\"fail to build k8s ApiClient\", e);\n        }\n    }\n\n}\n","sourceCodeStart":94,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/K8sUtils.java#L94-L117","documentation":"K8sUtils.buildClient(configYaml) parses the provided kubeconfig YAML with Config.fromKubeconfig and builds a KubernetesClient, wrapping any failure in a TaskException 'fail to build k8s ApiClient'. It fires when the YAML is invalid or the client cannot be constructed from it (bad fields, missing server, expired certs).","triggerScenarios":"Calling buildClient() with a malformed or empty kubeconfig YAML string, YAML that fails Fabric8 Config parsing, or a config referencing unreachable/invalid server URLs or certificates.","commonSituations":"K8s config YAML stored in a tenant/resource is truncated or has wrong indentation; a service-account token was rotated; users paste a '~/.kube/config' with multi-document YAML unsupported by parsing; environment variable expansion left placeholders like ${K8S_API_SERVER} unresolved.","solutions":["Validate the kubeconfig YAML locally: KUBECONFIG=<file> kubectl cluster-info.","Check that the configYaml string is complete, valid YAML, single kubeconfig document.","Verify server URL, CA certificate, and token/client-cert fields are present and not placeholders.","Regenerate credentials if the token/cert expired, then rebuild the client.","Confirm the Fabric8 client dependency version is compatible with your cluster."],"exampleFix":"// before\nString configYaml = System.getenv(\"K8S_CONFIG\"); // null or placeholder text\nk8sUtils.buildClient(configYaml);\n// after\nString configYaml = Objects.requireNonNull(System.getenv(\"K8S_CONFIG\"), \"K8S_CONFIG not set\");\nYaml yaml = new Yaml();\nyaml.load(configYaml); // validate parseable before building\nk8sUtils.buildClient(configYaml);","handlingStrategy":"validation","validationCode":"if (configYaml == null || configYaml.trim().isEmpty()) {\n    throw new IllegalStateException(\"kubeconfig yaml is empty\");\n}\nnew Yaml().load(configYaml); // throws early if not valid YAML","typeGuard":"boolean isValidKubeconfig(String yaml) {\n    try {\n        Object o = new Yaml().load(yaml);\n        return o instanceof Map && ((Map<?, ?>) o).containsKey(\"clusters\");\n    } catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n    k8sUtils.buildClient(configYaml);\n} catch (TaskException e) {\n    throw new IllegalStateException(\"invalid kubeconfig for K8s tasks\", e);\n}","preventionTips":["Validate kubeconfig YAML with kubectl before storing it in DolphinScheduler resources.","Avoid placeholder variables in stored kubeconfigs; resolve env substitutions at deploy time.","Rotate tokens/credentials proactively and re-run buildClient as a startup health check."],"tags":["kubernetes","kubeconfig","client-initialization"],"backgroundTag":"yaml-parse-error","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}