kubernetes/kops · error

parsing file %q: %v

Error message

parsing file %q: %v

What it means

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.

Source

Thrown at cmd/kops/delete.go:103

		var contents []byte
		var err error
		if f == "-" {
			contents, err = ConsumeStdin()
			if err != nil {
				return fmt.Errorf("reading from stdin: %v", err)
			}
		} else {
			contents, err = factory.VFSContext().ReadFile(f)
			if err != nil {
				return fmt.Errorf("reading file %q: %v", f, err)
			}
		}

		sections := text.SplitContentToSections(contents)
		for _, section := range sections {
			o, gvk, err := kopscodecs.Decode(section, nil)
			if err != nil {
				return fmt.Errorf("parsing file %q: %v", f, err)
			}

			switch v := o.(type) {
			case *kopsapi.Cluster:
				options := &DeleteClusterOptions{
					ClusterName: v.ObjectMeta.Name,
					Yes:         d.Yes,
				}
				err = RunDeleteCluster(ctx, factory, out, options)
				if err != nil {
					return err
				}
				deletedClusters.Insert(v.ObjectMeta.Name)
			case *kopsapi.InstanceGroup:
				options := &DeleteInstanceGroupOptions{
					GroupName:   v.ObjectMeta.Name,
					ClusterName: v.ObjectMeta.Labels[kopsapi.LabelClusterName],
					Yes:         d.Yes,

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the file contains only kOps resources with correct `apiVersion: kops.k8s.io/v1alpha2` and `kind:` fields.
  2. Validate the manifest structure against `kops get <cluster> -o yaml` output for the installed kOps version.
  3. Split mixed manifests: delete k8s resources with kubectl, kOps resources with kops delete.

Example fix

// before (kind unknown to kopscodecs)
kind: Deployment
apiVersion: apps/v1
// after
kind: Cluster
apiVersion: kops.k8s.io/v1alpha2
metadata:
  name: c.example.com
Defensive patterns

Strategy: validation

Validate before calling

const yaml = require('js-yaml');
for (const doc of yaml.loadAll(fs.readFileSync(f, 'utf8'))) {
  if (!doc || !doc.apiVersion || !doc.kind) throw new Error(`Missing apiVersion/kind in ${f}`);
  if (!doc.apiVersion.startsWith('kops.k8s.io/')) throw new Error(`${doc.kind} is not a kOps resource`);
}

Type guard

function isKopsManifest(doc) {
  return doc && typeof doc === 'object' &&
    typeof doc.apiVersion === 'string' && doc.apiVersion.startsWith('kops.k8s.io/') &&
    typeof doc.kind === 'string';
}

Try / catch

try {
  runKops(['delete', '-f', manifestPath]);
} catch (e) {
  if (/parsing file/.test(e.message)) {
    console.error('Manifest does not decode to a kOps object; check kind/apiVersion/schema.');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/72aed15cb5891eb4. Report an issue: GitHub.