apolloconfig/apollo · error · BadRequestException

can not delete default cluster!

Error message

can not delete default cluster!

What it means

A BadRequestException (HTTP 400) thrown from ClusterController.delete() (DELETE /apps/{appId}/clusters/{clusterName}) when the cluster being deleted is the default cluster (name equals ConfigConsts.CLUSTER_NAME_DEFAULT, i.e. "default"). Apollo forbids deleting the default cluster because every application requires exactly one; it is the root cluster from which other clusters branch.

Source

Thrown at apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ClusterController.java:77

    } else {
      entity = clusterService.saveWithoutInstanceOfAppNamespaces(entity);
    }

    return BeanUtils.transform(ClusterDTO.class, entity);
  }

  @DeleteMapping("/apps/{appId}/clusters/{clusterName:.+}")
  public void delete(@PathVariable("appId") String appId,
      @PathVariable("clusterName") String clusterName, @RequestParam String operator) {

    Cluster entity = clusterService.findOne(appId, clusterName);

    if (entity == null) {
      throw NotFoundException.clusterNotFound(appId, clusterName);
    }

    if (ConfigConsts.CLUSTER_NAME_DEFAULT.equals(entity.getName())) {
      throw new BadRequestException("can not delete default cluster!");
    }

    clusterService.delete(entity.getId(), operator);
  }

  @GetMapping("/apps/{appId}/clusters")
  public List<ClusterDTO> find(@PathVariable("appId") String appId) {
    List<Cluster> clusters = clusterService.findParentClusters(appId);
    return BeanUtils.batchTransform(ClusterDTO.class, clusters);
  }

  @GetMapping("/apps/{appId}/clusters/{clusterName:.+}")
  public ClusterDTO get(@PathVariable("appId") String appId,
      @PathVariable("clusterName") String clusterName) {
    Cluster cluster = clusterService.findOne(appId, clusterName);
    if (cluster == null) {
      throw NotFoundException.clusterNotFound(appId, clusterName);
    }

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Exclude the default cluster from any automated deletion loop.
  2. If you need to reset the default cluster's contents, delete/edit its namespaces and items individually instead of the cluster itself.
  3. Add a guard in client code: skip clusters where name equals 'default' before calling the delete endpoint.

Example fix

// before: deletes all clusters including default
for (ClusterDTO cluster : clusters) {
    clusterApi.delete(appId, env, cluster.getName());
}

// after: skip the default cluster
for (ClusterDTO cluster : clusters) {
    if (!"default".equals(cluster.getName())) {
        clusterApi.delete(appId, env, cluster.getName());
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Skip the default cluster in any deletion loop
if ("default".equals(cluster.getName())) {
    return; // never delete the default cluster
}
clusterApi.delete(appId, env, cluster.getName());

Prevention

When it happens

Trigger: DELETE /apps/{appId}/clusters/default (or the localized default cluster name) when the resolved cluster entity name equals ConfigConsts.CLUSTER_NAME_DEFAULT.

Common situations: Automated cleanup scripts that iterate all clusters and attempt to delete each one without excluding 'default'; a UI bug that renders a delete button for the default cluster; attempting to reset an environment by deleting all clusters.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/c07c4d2c4c2045e1. Report an issue: GitHub.