{"record":{"id":"72aed15cb5891eb4","repo":"kubernetes/kops","slug":"parsing-file-q-v","errorCode":null,"errorMessage":"parsing file %q: %v","messagePattern":"parsing file %q: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/delete.go","lineNumber":103,"sourceCode":"\t\tvar contents []byte\n\t\tvar err error\n\t\tif f == \"-\" {\n\t\t\tcontents, err = ConsumeStdin()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"reading from stdin: %v\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tcontents, err = factory.VFSContext().ReadFile(f)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"reading file %q: %v\", f, err)\n\t\t\t}\n\t\t}\n\n\t\tsections := text.SplitContentToSections(contents)\n\t\tfor _, section := range sections {\n\t\t\to, gvk, err := kopscodecs.Decode(section, nil)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"parsing file %q: %v\", f, err)\n\t\t\t}\n\n\t\t\tswitch v := o.(type) {\n\t\t\tcase *kopsapi.Cluster:\n\t\t\t\toptions := &DeleteClusterOptions{\n\t\t\t\t\tClusterName: v.ObjectMeta.Name,\n\t\t\t\t\tYes:         d.Yes,\n\t\t\t\t}\n\t\t\t\terr = RunDeleteCluster(ctx, factory, out, options)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tdeletedClusters.Insert(v.ObjectMeta.Name)\n\t\t\tcase *kopsapi.InstanceGroup:\n\t\t\t\toptions := &DeleteInstanceGroupOptions{\n\t\t\t\t\tGroupName:   v.ObjectMeta.Name,\n\t\t\t\t\tClusterName: v.ObjectMeta.Labels[kopsapi.LabelClusterName],\n\t\t\t\t\tYes:         d.Yes,","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/delete.go#L85-L121","documentation":"Returned when `kopscodecs.Decode` fails to parse a section of the file passed to `kops delete -f` into a known kOps API object. Each YAML/JSON section must decode to a registered kOps kind (Cluster, InstanceGroup, etc.); unknown kinds, bad structure, or non-kOps resources cause this error.","triggerScenarios":"Running `kops delete -f` on a file containing plain Kubernetes manifests (e.g. a Deployment), an unregistered kOps kind, malformed YAML/JSON, or a document missing required fields like apiVersion/kind that the codec needs.","commonSituations":"Reusing a manifest file that mixes kops cluster specs with regular k8s resources; a kOps output file edited until it no longer matches the schema; API version drift after upgrading kops (older spec versions no longer decoded).","solutions":["Check the file contains only kOps resources with correct `apiVersion: kops.k8s.io/v1alpha2` and `kind:` fields.","Validate the manifest structure against `kops get <cluster> -o yaml` output for the installed kOps version.","Split mixed manifests: delete k8s resources with kubectl, kOps resources with kops delete."],"exampleFix":"// before (kind unknown to kopscodecs)\nkind: Deployment\napiVersion: apps/v1\n// after\nkind: Cluster\napiVersion: kops.k8s.io/v1alpha2\nmetadata:\n  name: c.example.com","handlingStrategy":"validation","validationCode":"const yaml = require('js-yaml');\nfor (const doc of yaml.loadAll(fs.readFileSync(f, 'utf8'))) {\n  if (!doc || !doc.apiVersion || !doc.kind) throw new Error(`Missing apiVersion/kind in ${f}`);\n  if (!doc.apiVersion.startsWith('kops.k8s.io/')) throw new Error(`${doc.kind} is not a kOps resource`);\n}","typeGuard":"function isKopsManifest(doc) {\n  return doc && typeof doc === 'object' &&\n    typeof doc.apiVersion === 'string' && doc.apiVersion.startsWith('kops.k8s.io/') &&\n    typeof doc.kind === 'string';\n}","tryCatchPattern":"try {\n  runKops(['delete', '-f', manifestPath]);\n} catch (e) {\n  if (/parsing file/.test(e.message)) {\n    console.error('Manifest does not decode to a kOps object; check kind/apiVersion/schema.');\n  }\n  throw e;\n}","preventionTips":["Only feed kops-generated YAML (kops get -o yaml) back to kops delete","Keep kOps CLI and manifest apiVersion versions in sync","Separate plain k8s manifests from kOps manifests in your repo"],"tags":["cli","yaml","validation","codec","kops"],"backgroundTag":"schema-validation-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"}