quarkusio/quarkus · error · IllegalStateException
A Deployment with no label in the label selector was request
Error message
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).
What it means
The inverse of the missing-label case: the new build requests a Deployment whose label selector has NO version label, but the existing Deployment's selector includes the version label. Since selectors are immutable, the change cannot be applied and Quarkus throws.
Source
Thrown at extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java:428
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));
}
}
return Optional.empty();
}
}View on GitHub (pinned to e1c734241f)
Solutions
- Delete the previous Deployment (kubectl delete deployment <name>) and redeploy.
- Set quarkus.kubernetes.add-version-to-label-selectors=true so the requested selector matches the existing one.
- Manually keep the version label consistent across environments by standardizing the property in a shared config profile.
Example fix
// before quarkus.kubernetes.add-version-to-label-selectors=false // deployed selector has version label // after quarkus.kubernetes.add-version-to-label-selectors=true
Defensive patterns
Strategy: validation
Validate before calling
// Detect existing Deployment's selector still carrying the version label before disabling 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 includes") && e.getMessage().contains("ensure the")) {
client.apps().deployments().inNamespace(ns).withName(name).delete();
deploy();
} else { throw e; }
} Prevention
- Never toggle add-version-to-label-selectors on clusters with existing Deployments without deleting them first.
- Keep the property identical across all profiles (dev/test/prod).
- Document selector-affecting properties in the team's deploy runbook.
When it happens
Trigger: quarkus.<target>.add-version-to-label-selectors=false (or the version label otherwise removed) while the deployed Deployment was created with the version label in its selector.
Common situations: Disabling add-version-to-label-selectors after having deployed with it enabled; older CI pipeline config deploying against a cluster provisioned by a newer config with the label.
Related errors
- A previous Deployment with a conflicting label %s=%s was fou
- A Deployment with a conflicting label %s=%s was in the label
- Openshift was requested as a deployment, but the target clus
- Cannot find ClassLoadingRecorder.class on classpath
- Couldn't fetch '' class from index
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/515f4b3c0c67c831.
Report an issue: GitHub.