apache/dolphinscheduler · error · ServiceException
120034
120034
Error message
this cluster has been used in namespace,so you can't delete it.
What it means
ClusterServiceImpl.deleteClusterByCode refuses to delete a cluster that is still referenced by one or more K8s namespaces. Before deleting, it counts namespaces linked to the cluster code via k8sNamespaceDao.countByClusterCode(code) and throws ServiceException(Status.DELETE_CLUSTER_RELATED_NAMESPACE_EXISTS, code 120034) when the count is > 0. This is a referential-integrity guard: deleting the cluster would leave orphaned namespace relations.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ClusterServiceImpl.java:199
return dto;
}
/**
* delete cluster
*
* @param loginUser login user
* @param code cluster code
*/
@Override
public void deleteClusterByCode(User loginUser, Long code) {
if (isNotAdmin(loginUser)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
long relatedNamespaceNumber = k8sNamespaceDao.countByClusterCode(code);
if (relatedNamespaceNumber > 0) {
throw new ServiceException(Status.DELETE_CLUSTER_RELATED_NAMESPACE_EXISTS);
}
if (clusterDao.deleteByCode(code)) {
return;
}
throw new ServiceException(Status.DELETE_CLUSTER_ERROR);
}
/**
* update cluster
*
* @param loginUser login user
* @param code cluster code
* @param name cluster name
* @param config cluster config
* @param desc cluster desc
*/
@OverrideView on GitHub (pinned to 02eac45a1b)
Solutions
- Delete all namespaces associated with the cluster first (K8s namespace management page or k8sNamespaceDao.deleteByClusterCode), then retry the cluster delete.
- Verify which namespaces reference the cluster by querying the k8s namespace table/list API filtered by cluster code.
- If the namespace rows are stale/orphaned (namespace no longer exists in K8s), remove them manually from the database (t_ds_k8s_namespace) and retry.
- Only after the related namespace count reaches 0 will deleteClusterByCode succeed.
Example fix
// before: delete cluster directly
clusterService.deleteClusterByCode(loginUser, clusterCode);
// after: clean up related namespaces first
List<K8sNamespace> ns = k8sNamespaceDao.queryByClusterCode(clusterCode);
if (!ns.isEmpty()) {
throw new IllegalStateException("Delete related namespaces first: " + ns.size());
}
clusterService.deleteClusterByCode(loginUser, clusterCode); Defensive patterns
Strategy: validation
Validate before calling
// Java
long nsCount = k8sNamespaceDao.countByClusterCode(clusterCode);
if (nsCount > 0) {
throw new IllegalStateException("Cluster " + clusterCode + " still has " + nsCount + " related namespaces");
} Try / catch
try {
clusterService.deleteClusterByCode(loginUser, code);
} catch (ServiceException e) {
if (e.getCode() == 120034) {
// prompt user to delete related namespaces first
} else {
throw e;
}
} Prevention
- Always delete dependent K8s namespaces as part of cluster teardown runbooks
- Track namespace-cluster relations in an inventory before deleting
- Automate cleanup of stale namespace rows for decommissioned clusters
When it happens
Trigger: Calling DELETE on the cluster API endpoint (or ClusterService.deleteClusterByCode) for a cluster whose code appears in the t_ds_k8s_namespace table. Happens even when the namespaces themselves are stale or the cluster is no longer actually running in K8s.
Common situations: Admins tearing down an environment: they remove a K8s cluster registration in the UI while namespace records created for that cluster (e.g. during workflow execution with K8s task type) were never cleaned up. Also occurs after partial deletes or when re-registering a cluster under a new code but leaving old namespace rows.
Related errors
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/d1ef595def4d1ff1.
Report an issue: GitHub.