{"record":{"id":"2ba76725e0015139","repo":"kubernetes/kops","slug":"failed-to-annotate-t","errorCode":null,"errorMessage":"Failed to annotate %T","messagePattern":"Failed to annotate %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/model/components/addonmanifests/remap.go","lineNumber":122,"sourceCode":"\n\t\tif err := iam.AddServiceAccountRole(&context.IAMModelContext, podSpec, subject); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif err := object.Set(podSpec, \"spec\", \"template\", \"spec\"); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set object: %w\", err)\n\t\t}\n\n\t}\n\treturn nil\n}\n\nfunc addLabels(addon *addonsapi.AddonSpec, objects kubemanifest.ObjectList) error {\n\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}","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/model/components/addonmanifests/remap.go#L104-L140","documentation":"addLabels reparses each manifest object's metadata into metav1.ObjectMeta to stamp kops ownership labels. If that reparse fails (metadata missing or not a valid ObjectMeta), the error is returned — but note it does not include the underlying parse error, only the Go type of the object, which makes diagnosing slightly harder.","triggerScenarios":"addLabels iteration where object.Reparse(meta, \"metadata\") fails on any object in the addon manifest: metadata block malformed, wrong type (e.g. metadata is a string), or unknown fields rejected under strict parsing.","commonSituations":"Hand-crafted addon YAML with typos in the metadata block; objects with empty/invalid metadata; manifests generated by other tools with non-standard metadata fields the strict decoder rejects.","solutions":["Check the object type named in the error (%T) and fix its metadata block to be a valid ObjectMeta","Validate the manifest YAML with kubectl --dry-run=client","Remove unknown fields from metadata","Restore the stock addon manifest from the matching channel"],"exampleFix":"# before (malformed)\nmetadata: kops-owned\n# after\nmetadata:\n  name: dns-controller\n  namespace: kube-system","handlingStrategy":"validation","validationCode":"// Pre-validate each object's metadata parses as ObjectMeta:\nmeta := &metav1.ObjectMeta{}\nif err := object.Reparse(meta, \"metadata\"); err != nil {\n    return fmt.Errorf(\"object %s/%s has invalid metadata: %v\", object.Kind(), object.GetNamespace(), err)\n}","typeGuard":"func hasValidMetadata(obj *kubemanifest.Object) bool {\n    var meta metav1.ObjectMeta\n    return obj.Reparse(&meta, \"metadata\") == nil\n}","tryCatchPattern":"if err := addLabels(addon, objects); err != nil {\n    if strings.HasPrefix(err.Error(), \"Failed to annotate\") {\n        // err lacks root cause; re-run Reparse per object to surface the real decode error\n        for _, obj := range objects {\n            var meta metav1.ObjectMeta\n            if rerr := obj.Reparse(&meta, \"metadata\"); rerr != nil { return fmt.Errorf(\"%v: %v\", err, rerr) }\n        }\n    }\n    return err\n}","preventionTips":["Ensure every manifest object has a well-formed metadata block","Avoid non-map labels structures in YAML","Validate manifests with a Kubernetes schema linter (e.g. kubeconform)"],"tags":["kops","metadata","labels","manifest-parsing"],"backgroundTag":"metadata-parse-failed","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"}