{"record":{"id":"efe92f66a087add5","repo":"kubernetes/kops","slug":"failed-to-parse-apiversion-q","errorCode":null,"errorMessage":"failed to parse apiVersion %q","messagePattern":"failed to parse apiVersion %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/channels/prune.go","lineNumber":55,"sourceCode":"\n// Prune prunes objects not in the manifest, according to PruneSpec.\nfunc (p *Pruner) Prune(ctx context.Context, manifest []byte, spec *api.PruneSpec) error {\n\tklog.Infof(\"Prune spec: %v\", spec)\n\n\tif spec == nil {\n\t\treturn nil\n\t}\n\n\tobjects, err := kubemanifest.LoadObjectsFrom(manifest)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse objects: %w\", err)\n\t}\n\n\tobjectsByKind := make(map[schema.GroupKind][]*kubemanifest.Object)\n\tfor _, object := range objects {\n\t\tgv, err := schema.ParseGroupVersion(object.APIVersion())\n\t\tif err != nil || gv.Version == \"\" {\n\t\t\treturn fmt.Errorf(\"failed to parse apiVersion %q\", object.APIVersion())\n\t\t}\n\t\tkind := object.Kind()\n\t\tif kind == \"\" {\n\t\t\treturn fmt.Errorf(\"failed to find kind in object\")\n\t\t}\n\n\t\tgvk := gv.WithKind(kind)\n\t\tgk := gvk.GroupKind()\n\t\tobjectsByKind[gk] = append(objectsByKind[gk], object)\n\t}\n\n\tfor i := range spec.Kinds {\n\t\tpruneKind := &spec.Kinds[i]\n\t\tgk := schema.GroupKind{Group: pruneKind.Group, Kind: pruneKind.Kind}\n\t\tif err := p.pruneObjectsOfKind(ctx, gk, pruneKind, objectsByKind[gk]); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to prune objects of kind %s: %w\", gk, err)\n\t\t}\n\t}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/channels/prune.go#L37-L73","documentation":"Every object in the manifest must carry a parseable apiVersion with a non-empty version so it can be mapped to a GroupVersion. If schema.ParseGroupVersion fails (e.g. apiVersion contains more than one '/') or the version is empty, Prune returns this error naming the bad apiVersion.","triggerScenarios":"A manifest document has `apiVersion: \"\"`, a missing apiVersion, or a malformed value like `apiVersion: apps/v1/extra`, or only a group with no version (`apiVersion: apps`).","commonSituations":"Hand-edited addon manifests omitting apiVersion; custom resource documents copied from docs using wrong apiVersion strings; generator output missing apiVersion on some documents.","solutions":["Set a valid apiVersion (`<group>/<version>`, or `v1` for core) on every document in the manifest","Validate with `kubectl apply --dry-run=client -f manifest.yaml` which reports missing/malformed apiVersions","Check the specific document named by the %q value in the error"],"exampleFix":"// before\nkind: Deployment\nmetadata:\n  name: web\n// after\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: web","handlingStrategy":"validation","validationCode":"func checkAPIVersions(manifest []byte) error {\n    objs, _ := kubemanifest.LoadObjectsFrom(manifest)\n    for _, o := range objs {\n        gv, err := schema.ParseGroupVersion(o.APIVersion())\n        if err != nil || gv.Version == \"\" {\n            return fmt.Errorf(\"bad apiVersion %q\", o.APIVersion())\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := pruner.Prune(ctx, manifest, spec); err != nil {\n    var bad string\n    if n, _ := fmt.Sscanf(err.Error(), \"failed to parse apiVersion %q\", &bad); n == 1 {\n        return fmt.Errorf(\"fix apiVersion %q in manifest\", bad)\n    }\n    return err\n}","preventionTips":["Run `kubectl apply --dry-run=client -f manifest.yaml` on every manifest in CI","Every document needs apiVersion (`group/version` or `v1`) — enforce with a CI schema check","Never hand-edit apiVersion without validating against `kubectl api-versions`"],"tags":["api-version","manifest","validation","kubernetes"],"backgroundTag":"invalid-apiversion","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}