{"record":{"id":"670ce79e9c3a3f84","repo":"apache/dolphinscheduler","slug":"namespace-s-does-not-exist-in-k8s-cluster-please","errorCode":null,"errorMessage":"namespace %s does not exist in k8s cluster, please create namespace in k8s cluster first","messagePattern":"namespace (.+?) does not exist in k8s cluster, please create namespace in k8s cluster first","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/k8s/K8sClientService.java","lineNumber":41,"sourceCode":"\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Component;\n\nimport io.fabric8.kubernetes.api.model.Namespace;\nimport io.fabric8.kubernetes.api.model.NamespaceList;\n\n/**\n * Encapsulates all client-related operations, not involving the db\n */\n@Component\npublic class K8sClientService {\n\n    @Autowired\n    private K8sManager k8sManager;\n\n    public void upsertNamespaceAndResourceToK8s(K8sNamespace k8sNamespace) {\n        if (!checkNamespaceToK8s(k8sNamespace.getNamespace(), k8sNamespace.getClusterCode())) {\n            throw new RuntimeException(String.format(\n                    \"namespace %s does not exist in k8s cluster, please create namespace in k8s cluster first\",\n                    k8sNamespace.getNamespace()));\n        }\n    }\n\n    private Optional<Namespace> getNamespaceFromK8s(String name, Long clusterCode) {\n        NamespaceList listNamespace =\n                k8sManager.getK8sClient(clusterCode).namespaces().list();\n\n        Optional<Namespace> list =\n                listNamespace.getItems().stream()\n                        .filter((Namespace namespace) -> namespace.getMetadata().getName().equals(name))\n                        .findFirst();\n\n        return list;\n    }\n\n    private boolean checkNamespaceToK8s(String name, Long clusterCode) {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/k8s/K8sClientService.java#L23-L59","documentation":"Thrown by K8sClientService.upsertNamespaceAndResourceToK8s as a plain RuntimeException when checkNamespaceToK8s finds that the requested namespace does not exist in the target Kubernetes cluster. DolphinScheduler requires the namespace to pre-exist in the cluster before it will upsert namespace resources (service account/label) for it.","triggerScenarios":"Calling upsertNamespaceAndResourceToK8s with a K8sNamespace whose namespace name cannot be found in the cluster identified by clusterCode — getNamespaceFromK8s returns empty for that name in that cluster context.","commonSituations":"Typo in namespace name; namespace created in a different cluster than the one registered by clusterCode; kubeconfig/credentials for the cluster wrong so the lookup fails; namespace deleted after being registered in DolphinScheduler UI; using a namespace that exists in k8s but was never created by an admin with proper RBAC.","solutions":["Create the namespace in the target Kubernetes cluster first: kubectl create namespace <name> against the cluster matching clusterCode","Verify the clusterCode maps to the cluster where the namespace actually exists","Check the cluster's kubeconfig/credentials in DolphinScheduler are valid and have RBAC to read namespaces","Re-check the namespace name for typos/case differences"],"exampleFix":"// before\nk8sClientService.upsertNamespaceAndResourceToK8s(k8sNamespace);\n// after\nRuntime.exec-less shell step:\n// kubectl config use-context <cluster-for-clusterCode>\n// kubectl create namespace <k8sNamespace.getNamespace()>\n// then call upsertNamespaceAndResourceToK8s(k8sNamespace);","handlingStrategy":"validation","validationCode":"boolean exists = k8sClient.namespaces()\n    .withName(k8sNamespace.getNamespace()) != null\n    && k8sClient.namespaces().withName(k8sNamespace.getNamespace()).get() != null;\nif (!exists) {\n    throw new IllegalStateException(\"Create namespace \" + k8sNamespace.getNamespace() + \" in k8s first\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create namespaces in the cluster before registering them in DolphinScheduler","Confirm clusterCode points to the cluster where the namespace lives","Validate kubeconfig/credentials and RBAC read access to namespaces","Check namespace name spelling and case before calling"],"tags":["kubernetes","namespace","validation"],"backgroundTag":"resource-not-found","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"}