quarkusio/quarkus · error · IllegalStateException

A Deployment with a conflicting label %s=%s was in the label

Error message

A Deployment with a conflicting label %s=%s was in the label selector was requested (previous had no such label). As the label selector is immutable, you need to either manually delete previous deployment, or remove the label (consider using quarkus.%s.add-version-to-label-selectors=false).

What it means

The new build requests a version label in the Deployment's label selector, but the existing Deployment in the cluster was created without one. Because label selectors are immutable, Kubernetes cannot update the existing Deployment to the new selector, so Quarkus throws before applying.

Source

Thrown at extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java:424

        if (existing.isEmpty()) {
            return;
        }

        if (resource instanceof Deployment deployment) {
            Optional<String> version = getLabelSelectorVersion(deployment);
            final var hasMetadata = existing.get();
            Optional<String> existingVersion = Optional.empty();
            if (hasMetadata instanceof Deployment existingDeployment) {
                existingVersion = getLabelSelectorVersion(existingDeployment);
            }
            if (version.isPresent() && existingVersion.isPresent()) {
                if (!version.get().equals(existingVersion.get())) {
                    throw new IllegalStateException(String.format(
                            "A previous Deployment with a conflicting label %s=%s was found in the label selector (current is %s=%s). As the label selector is immutable, you need to either align versions or manually delete previous deployment.",
                            VERSION_LABEL, existingVersion.get(), VERSION_LABEL, version.get()));
                }
            } else if (version.isPresent()) {
                throw new IllegalStateException(String.format(
                        "A Deployment with a conflicting label %s=%s was in the label selector was requested (previous had no such label). As the label selector is immutable, you need to either manually delete previous deployment, or remove the label (consider using quarkus.%s.add-version-to-label-selectors=false).",
                        VERSION_LABEL, version.get(), deploymnetTarget.getName().toLowerCase()));
            } else if (existingVersion.isPresent()) {
                throw new IllegalStateException(String.format(
                        "A Deployment with no label in the label selector was requested (previous includes %s=%s). As the label selector is immutable, you need to either manually delete previous deployment, or ensure the %s label is present (consider using quarkus.%s.add-version-to-label-selectors=true).",
                        VERSION_LABEL, existingVersion.get(), VERSION_LABEL, deploymnetTarget.getName().toLowerCase()));
            }
        }
    }

    private static Optional<String> getLabelSelectorVersion(Deployment deployment) {
        final var spec = deployment.getSpec();
        if (spec != null) {
            final var selector = spec.getSelector();
            if (selector != null) {
                return Optional.ofNullable(selector.getMatchLabels())
                        .map(m -> m.get(VERSION_LABEL));
            }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Delete the previous Deployment (kubectl delete deployment <name>) and redeploy so the new selector applies cleanly.
  2. Set quarkus.kubernetes.add-version-to-label-selectors=false (use quarkus.openshift.add-version-to-label-selectors=false for OpenShift) to match the old selector.
  3. Apply the new resources to a differently named Deployment to avoid selector conflict.

Example fix

// before
quarkus.kubernetes.add-version-to-label-selectors=true // old Deployment has no version label
// after
quarkus.kubernetes.add-version-to-label-selectors=false
Defensive patterns

Strategy: validation

Validate before calling

// Detect that the existing Deployment's selector has no version label before enabling the feature
Deployment existing = client.apps().deployments().inNamespace(ns).withName(name).get();
boolean hasVersionLabel = existing != null && existing.getSpec().getSelector()
    .getMatchLabels().containsKey("app.kubernetes.io/version");
if (existing != null && !hasVersionLabel && addVersionToLabelSelectors) {
    client.apps().deployments().inNamespace(ns).withName(name).delete(); // pre-clean
}

Try / catch

try {
    deploy();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("previous had no such label")) {
        client.apps().deployments().inNamespace(ns).withName(name).delete();
        deploy();
    } else { throw e; }
}

Prevention

When it happens

Trigger: quarkus.<target>.add-version-to-label-selectors=true (or default on) now, while the existing Deployment was created earlier with the label absent from its selector.

Common situations: Enabling add-version-to-label-selectors after an initial deployment; upgrading a Quarkus application that previously deployed without the version label; deploying an app whose old Deployment predates the label feature.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/a68cda351da7fe20. Report an issue: GitHub.