kubernetes/kops · error

error parsing %s: %v

Error message

error parsing %s: %v

What it means

readConfig() successfully read the object's bytes but kopscodecs.Decode could not parse them into a runtime.Object. This indicates the stored manifest is corrupt, empty, in an unrecognized format, or from an incompatible schema version.

Source

Thrown at pkg/client/simple/vfsclientset/commonvfs.go:129

	if err != nil {
		return nil, fmt.Errorf("error encoding object: %v", err)
	}

	return b.Bytes(), nil
}

func (c *VFSClientBase) readConfig(ctx context.Context, configPath vfs.Path) (runtime.Object, error) {
	data, err := configPath.ReadFile(ctx)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, err
		}
		return nil, fmt.Errorf("error reading %s: %v", configPath, err)
	}

	object, _, err := kopscodecs.Decode(data, nil)
	if err != nil {
		return nil, fmt.Errorf("error parsing %s: %v", configPath, err)
	}
	return object, nil
}

func (c *VFSClientBase) writeConfig(ctx context.Context, cluster *kops.Cluster, configPath vfs.Path, o runtime.Object, writeOptions ...vfs.WriteOption) error {
	data, err := c.serialize(o)
	if err != nil {
		return fmt.Errorf("error marshaling object: %v", err)
	}

	create := false
	for _, writeOption := range writeOptions {
		switch writeOption {
		case vfs.WriteOptionCreate:
			create = true
		case vfs.WriteOptionOnlyIfExists:
			_, err = configPath.ReadFile(ctx)
			if err != nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Download the offending file from the state store and inspect it for corruption or wrong apiVersion.
  2. Fix or restore the manifest (e.g. via `kops get -o yaml` from a backup, or git-versioned copy).
  3. Ensure the kops CLI version is compatible with the cluster state version.
  4. Re-upload the file with a valid kops API version (e.g. kops.k8s.io/v1alpha2 as appropriate).

Example fix

// before (state store file)
apiVersion: v1alpha1  # unknown to current codecs
kind: Cluster
// after
apiVersion: kops.k8s.io/v1alpha2
kind: Cluster
Defensive patterns

Strategy: validation

Validate before calling

data, err := readRawFromStateStore(ctx, path)
if err != nil { return err }
if len(bytes.TrimSpace(data)) == 0 {
    return fmt.Errorf("state file %s is empty/corrupt", path)
}
if !bytes.Contains(data, []byte("apiVersion:")) {
    return fmt.Errorf("state file %s is not a kubernetes-style manifest", path)
}

Try / catch

if err := client.Get(ctx, name); err != nil && strings.Contains(err.Error(), "error parsing") {
    // restore the manifest from backup before retrying
}

Prevention

When it happens

Trigger: Find/Get on a vfs clientset where the file exists but its contents fail kopscodecs.Decode — truncated upload, YAML/JSON not matching kops API, unknown apiVersion, or manual edits.

Common situations: Manually edited YAML in the S3 state bucket with wrong apiVersion; interrupted `kops replace`/upload leaving a partial file; kops version upgrade changing codecs; garbage/corruption in the bucket object.

Related errors


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