{"record":{"id":"515f4b3c0c67c831","repo":"quarkusio/quarkus","slug":"a-deployment-with-no-label-in-the-label-selector-w","errorCode":null,"errorMessage":"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).","messagePattern":"A Deployment with no label in the label selector was requested \\(previous includes (.+?)=(.+?)\\)\\. As the label selector is immutable, you need to either manually delete previous deployment, or ensure the (.+?) label is present \\(consider using quarkus\\.(.+?)\\.add-version-to-label-selectors=true\\)\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java","lineNumber":428,"sourceCode":"        if (resource instanceof Deployment deployment) {\n            Optional<String> version = getLabelSelectorVersion(deployment);\n            final var hasMetadata = existing.get();\n            Optional<String> existingVersion = Optional.empty();\n            if (hasMetadata instanceof Deployment existingDeployment) {\n                existingVersion = getLabelSelectorVersion(existingDeployment);\n            }\n            if (version.isPresent() && existingVersion.isPresent()) {\n                if (!version.get().equals(existingVersion.get())) {\n                    throw new IllegalStateException(String.format(\n                            \"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.\",\n                            VERSION_LABEL, existingVersion.get(), VERSION_LABEL, version.get()));\n                }\n            } else if (version.isPresent()) {\n                throw new IllegalStateException(String.format(\n                        \"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).\",\n                        VERSION_LABEL, version.get(), deploymnetTarget.getName().toLowerCase()));\n            } else if (existingVersion.isPresent()) {\n                throw new IllegalStateException(String.format(\n                        \"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).\",\n                        VERSION_LABEL, existingVersion.get(), VERSION_LABEL, deploymnetTarget.getName().toLowerCase()));\n            }\n        }\n    }\n\n    private static Optional<String> getLabelSelectorVersion(Deployment deployment) {\n        final var spec = deployment.getSpec();\n        if (spec != null) {\n            final var selector = spec.getSelector();\n            if (selector != null) {\n                return Optional.ofNullable(selector.getMatchLabels())\n                        .map(m -> m.get(VERSION_LABEL));\n            }\n        }\n        return Optional.empty();\n    }\n}","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java#L410-L446","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nquarkus.kubernetes.add-version-to-label-selectors=false // deployed selector has version label\n// after\nquarkus.kubernetes.add-version-to-label-selectors=true","handlingStrategy":"validation","validationCode":"// Detect existing Deployment's selector still carrying the version label before disabling the feature\nDeployment existing = client.apps().deployments().inNamespace(ns).withName(name).get();\nboolean hasVersionLabel = existing != null && existing.getSpec().getSelector()\n    .getMatchLabels().containsKey(\"app.kubernetes.io/version\");\nif (existing != null && hasVersionLabel && !addVersionToLabelSelectors) {\n    client.apps().deployments().inNamespace(ns).withName(name).delete(); // pre-clean\n}","typeGuard":null,"tryCatchPattern":"try {\n    deploy();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"previous includes\") && e.getMessage().contains(\"ensure the\")) {\n        client.apps().deployments().inNamespace(ns).withName(name).delete();\n        deploy();\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["kubernetes","deployment","label-selector","immutable"],"backgroundTag":"kubernetes-immutable-label-selector","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}