{"record":{"id":"07ceebe1ff1b9702","repo":"apache/dolphinscheduler","slug":"k8s-namespace-not-exist","errorCode":"K8S_NAMESPACE_NOT_EXIST","errorMessage":"K8S_NAMESPACE_NOT_EXIST","messagePattern":"K8S_NAMESPACE_NOT_EXIST","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java","lineNumber":210,"sourceCode":"        return result;\n    }\n\n    /**\n     * delete namespace by id\n     *\n     * @param loginUser login user\n     * @param id        namespace id\n     */\n    @Override\n    public void deleteNamespaceById(User loginUser, int id) {\n        if (isNotAdmin(loginUser)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        K8sNamespace k8sNamespaceObj = k8sNamespaceDao.queryById(id);\n        if (k8sNamespaceObj == null) {\n            log.error(\"K8s namespace does not exist, namespaceId:{}.\", id);\n            throw new ServiceException(Status.K8S_NAMESPACE_NOT_EXIST, id);\n        }\n\n        k8sNamespaceDao.deleteById(id);\n        log.info(\"K8s namespace delete complete, namespace:{}.\", k8sNamespaceObj.getNamespace());\n    }\n\n    /**\n     * check namespace name exist\n     *\n     * @param namespace namespace\n     * @return true if the k8s and namespace not exists, otherwise return false\n     */\n    private boolean checkNamespaceExistInDb(String namespace, Long clusterCode) {\n        return k8sNamespaceDao.existNamespace(namespace, clusterCode);\n    }\n\n    /**\n     * query unauthorized namespace","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java#L192-L228","documentation":"K8S_NAMESPACE_NOT_EXIST is thrown by K8sNamespaceServiceImpl.deleteNamespaceById when k8sNamespaceDao.queryById(id) returns null, meaning no K8s namespace record exists with the given id in t_ds_k8s_namespace. The delete is aborted and the id is reported in the message. It is a pre-delete existence check, not a Kubernetes-side error.","triggerScenarios":"Calling DELETE /k8s-namespace/{id} with an id that was already deleted; a stale id cached from a list call before another admin deleted the namespace; a wrong/typo id; referencing an id from a different environment's database.","commonSituations":"Double-delete in retry logic; concurrent admin deletions racing; UI stale list data; automation scripts with hard-coded ids after the table was rebuilt.","solutions":["Refresh the namespace list (GET /k8s-namespace/list) and confirm the id still exists before deleting.","Treat this error as idempotent success if the goal is 'ensure the namespace is gone'.","Correct the id in the script/UI payload; delete by the current namespace's id.","Check t_ds_k8s_namespace directly (SELECT * FROM t_ds_k8s_namespace WHERE id=...) if you suspect data issues."],"exampleFix":"// before\nk8sNamespaceService.deleteNamespaceById(admin, 42); // may throw if already deleted\n\n// after\nif (k8sNamespaceDao.queryById(42) != null) {\n    k8sNamespaceService.deleteNamespaceById(admin, 42);\n}","handlingStrategy":"validation","validationCode":"// Check existence before delete\nK8sNamespace ns = k8sNamespaceDao.queryById(id);\nif (ns == null) {\n    log.info(\"namespace id {} already gone; skipping delete\", id);\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    service.deleteNamespaceById(admin, id);\n} catch (ServiceException e) {\n    if (Status.K8S_NAMESPACE_NOT_EXIST.getCode() == e.getCode()) {\n        log.info(\"namespace {} already deleted; treating as idempotent success\", id);\n        return;\n    }\n    throw e;\n}","preventionTips":["Refresh the namespace list before delete operations instead of caching ids.","Handle double-delete gracefully: treat K8S_NAMESPACE_NOT_EXIST as success in cleanup scripts.","Avoid hard-coded namespace ids; look them up by name at runtime."],"tags":["resource-not-found","kubernetes","delete"],"backgroundTag":"record-not-found","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}