apache/dolphinscheduler · error · ServiceException

K8S_NAMESPACE_NOT_EXIST

K8S_NAMESPACE_NOT_EXIST

Error message

K8S_NAMESPACE_NOT_EXIST

What it means

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.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java:210

        return result;
    }

    /**
     * delete namespace by id
     *
     * @param loginUser login user
     * @param id        namespace id
     */
    @Override
    public void deleteNamespaceById(User loginUser, int id) {
        if (isNotAdmin(loginUser)) {
            throw new ServiceException(Status.USER_NO_OPERATION_PERM);
        }

        K8sNamespace k8sNamespaceObj = k8sNamespaceDao.queryById(id);
        if (k8sNamespaceObj == null) {
            log.error("K8s namespace does not exist, namespaceId:{}.", id);
            throw new ServiceException(Status.K8S_NAMESPACE_NOT_EXIST, id);
        }

        k8sNamespaceDao.deleteById(id);
        log.info("K8s namespace delete complete, namespace:{}.", k8sNamespaceObj.getNamespace());
    }

    /**
     * check namespace name exist
     *
     * @param namespace namespace
     * @return true if the k8s and namespace not exists, otherwise return false
     */
    private boolean checkNamespaceExistInDb(String namespace, Long clusterCode) {
        return k8sNamespaceDao.existNamespace(namespace, clusterCode);
    }

    /**
     * query unauthorized namespace

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Refresh the namespace list (GET /k8s-namespace/list) and confirm the id still exists before deleting.
  2. Treat this error as idempotent success if the goal is 'ensure the namespace is gone'.
  3. Correct the id in the script/UI payload; delete by the current namespace's id.
  4. Check t_ds_k8s_namespace directly (SELECT * FROM t_ds_k8s_namespace WHERE id=...) if you suspect data issues.

Example fix

// before
k8sNamespaceService.deleteNamespaceById(admin, 42); // may throw if already deleted

// after
if (k8sNamespaceDao.queryById(42) != null) {
    k8sNamespaceService.deleteNamespaceById(admin, 42);
}
Defensive patterns

Strategy: validation

Validate before calling

// Check existence before delete
K8sNamespace ns = k8sNamespaceDao.queryById(id);
if (ns == null) {
    log.info("namespace id {} already gone; skipping delete", id);
    return;
}

Try / catch

try {
    service.deleteNamespaceById(admin, id);
} catch (ServiceException e) {
    if (Status.K8S_NAMESPACE_NOT_EXIST.getCode() == e.getCode()) {
        log.info("namespace {} already deleted; treating as idempotent success", id);
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Double-delete in retry logic; concurrent admin deletions racing; UI stale list data; automation scripts with hard-coded ids after the table was rebuilt.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/07ceebe1ff1b9702. Report an issue: GitHub.