{"record":{"id":"655c3998ffedffc9","repo":"quarkusio/quarkus","slug":"a-previous-deployment-with-a-conflicting-label-s","errorCode":null,"errorMessage":"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.","messagePattern":"A previous Deployment with a conflicting label (.+?)=(.+?) was found in the label selector \\(current is (.+?)=(.+?)\\)\\. As the label selector is immutable, you need to either align versions or manually delete previous deployment\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java","lineNumber":419,"sourceCode":"                Boolean.TRUE) == null;\n    }\n\n    private static void checkLabelSelectorVersions(DeploymentTargetEntry deploymnetTarget, HasMetadata resource,\n            Optional<HasMetadata> existing) {\n        if (existing.isEmpty()) {\n            return;\n        }\n\n        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) {","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesDeployer.java#L401-L437","documentation":"The Kubernetes deployer compares the version label (app.kubernetes.io/version or the configured VERSION_LABEL) in the label selector of an existing Deployment with the version requested by the current build. Kubernetes label selectors are immutable, so a mismatch means the new Deployment cannot replace the old one. Quarkus fails fast with this error instead of letting the Kubernetes API reject the apply.","triggerScenarios":"quarkus.kubernetes.deploy=true with a previously applied Deployment whose label selector contains a different value for the version label than the version computed for the new build (e.g. project version changed, or quarkus.kubernetes.version was changed).","commonSituations":"Developers bump the project version or change quarkus.kubernetes.version after having already deployed once; CI deploying with a different version than what was originally applied; toggling quarkus.<target>.add-version-to-label-selectors between builds.","solutions":["Align the version: redeploy with the same version label as the existing Deployment (restore the previous quarkus.kubernetes.version / project version).","Delete the previous Deployment from the cluster (kubectl delete deployment <name> -n <namespace>) and deploy again.","Set quarkus.kubernetes.add-version-to-label-selectors=false so the version label is excluded from the label selector."],"exampleFix":"// before (application.properties)\nquarkus.kubernetes.version=1.0.1 // conflicts with deployed 1.0.0 selector\n// after\nquarkus.kubernetes.add-version-to-label-selectors=false\nquarkus.kubernetes.version=1.0.1","handlingStrategy":"validation","validationCode":"// Before deploying, check the version label of the existing Deployment\nDeployment existing = client.apps().deployments().inNamespace(ns).withName(name).get();\nString deployedVersion = existing != null\n    ? existing.getMetadata().getLabels().get(\"app.kubernetes.io/version\") : null;\nif (deployedVersion != null && !deployedVersion.equals(expectedVersion)) {\n    throw new IllegalStateException(\"Version label mismatch: deployed=\" + deployedVersion\n        + \" requested=\" + expectedVersion + \" — delete the Deployment or align versions\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    deployer.deploy(...);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"conflicting label\") && e.getMessage().contains(\"label selector is immutable\")) {\n        client.apps().deployments().inNamespace(ns).withName(name).delete();\n        deployer.deploy(...); // retry once after cleanup\n    } else { throw e; }\n}","preventionTips":["Keep the application version stable across CI/CD runs or always delete before re-deploying in ephemeral environments.","Standardize quarkus.kubernetes.add-version-to-label-selectors across all environments from day one.","Use distinct namespaces per version/branch in dev/CI to avoid stale Deployments."],"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"}