{"record":{"id":"4ffb56b8be8148fa","repo":"kubernetes/kops","slug":"label-q-already-set-to-q-while-it-should-be-q","errorCode":null,"errorMessage":"label %q already set to %q while it should be %q","messagePattern":"label %q already set to %q while it should be %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/model/components/addonmanifests/remap.go","lineNumber":136,"sourceCode":"\tfor _, object := range objects {\n\t\tmeta := &metav1.ObjectMeta{}\n\t\terr := object.Reparse(meta, \"metadata\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to annotate %T\", object)\n\t\t}\n\n\t\tif meta.Labels == nil {\n\t\t\tmeta.Labels = make(map[string]string)\n\t\t}\n\n\t\tmeta.Labels[\"app.kubernetes.io/managed-by\"] = \"kops\"\n\t\tmeta.Labels[KopsAddonLabelKey] = *addon.Name\n\n\t\t// ensure selector is set where applicable\n\t\tfor key, val := range addon.Selector {\n\t\t\texistingVal, ok := meta.Labels[key]\n\t\t\tif ok && existingVal != val {\n\t\t\t\treturn fmt.Errorf(\"label %q already set to %q while it should be %q\", key, meta.Labels[key], val)\n\t\t\t}\n\n\t\t\tmeta.Labels[key] = val\n\t\t}\n\t\tif hasPodSpecTemplate(object) {\n\t\t\taddPodSpecLabels(object)\n\t\t}\n\t\tobject.Set(meta, \"metadata\")\n\t}\n\treturn nil\n}\n\nfunc addPodSpecLabels(object *kubemanifest.Object) error {\n\tpodMeta := &metav1.ObjectMeta{}\n\n\tif err := object.Reparse(podMeta, \"spec\", \"template\", \"metadata\"); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse spec.template.spec from Deployment: %v\", err)\n\t}","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/model/components/addonmanifests/remap.go#L118-L154","documentation":"addLabels enforces the addon's declared selector labels: before copying addon.Selector onto each object, it rejects objects where the label key already exists with a different value, since kops cannot reconcile contradictory ownership/selector labels. This prevents silently relabeling objects that intentionally carry different values.","triggerScenarios":"RemapAddonManifest on an addon whose AddonSpec.Selector declares key K=V, while an object in the manifest already has label K set to a value != V.","commonSituations":"Customized manifests where a user changed a selector label (e.g. k8s-app: kube-dns changed to k8s-app: my-dns); addon spec updated upstream to select on a new label that collides with an existing one; copy-pasted labels across addons.","solutions":["Change the object's existing label value to match the addon selector, or remove it so the selector value is applied","Update the AddonSpec selector to the value already present in the manifest if the existing value is intentional","Check for copy-pasted labels from another addon and reassign a unique key","Restore the stock manifest and re-apply your customization via supported overrides"],"exampleFix":"# before\nmetadata:\n  labels:\n    k8s-app: my-dns\n# after (match addon.Selector)\nmetadata:\n  labels:\n    k8s-app: kube-dns","handlingStrategy":"validation","validationCode":"// Detect selector conflicts before remapping:\nfor key, want := range addon.Selector {\n    for _, obj := range objects {\n        meta := &metav1.ObjectMeta{}\n        if err := obj.Reparse(meta, \"metadata\"); err != nil { continue }\n        if have, ok := meta.Labels[key]; ok && have != want {\n            return fmt.Errorf(\"conflict: %s has %s=%s, selector wants %s\", obj.Kind(), key, have, want)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := addLabels(addon, objects); err != nil {\n    var conflict *LabelConflictError\n    if errors.As(err, &conflict) { /* adjust selector or labels */ }\n    return fmt.Errorf(\"failed to annotate %q: %w\", name, err)\n}","preventionTips":["Keep object labels consistent with the Addon spec selector","Avoid reusing selector keys (like k8s-app) with different values across addons","Source custom manifests from the official channel and apply changes via selectors, not relabeling"],"tags":["kops","labels","selector","addon"],"backgroundTag":"label-conflict","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}