kubernetes/kops · error

error parsing yaml: %v

Error message

error parsing yaml: %v

What it means

After the editor closes, kOps passes the edited bytes to kopscodecs.Decode to parse them back into a typed API object. If the edited content is not valid YAML, or is valid YAML but not a decodable kops API object, this error wraps the decoder failure.

Source

Thrown at cmd/kops/create_instancegroup.go:278

		if err != nil {
			return err
		}
		ext := "yaml"

		// launch the editor
		edited, file, err := edit.LaunchTempFile(fmt.Sprintf("%s-edit-", filepath.Base(os.Args[0])), ext, bytes.NewReader(raw))
		defer func() {
			if file != "" {
				try.RemoveFile(file)
			}
		}()
		if err != nil {
			return fmt.Errorf("error launching editor: %v", err)
		}

		obj, _, err := kopscodecs.Decode(edited, nil)
		if err != nil {
			return fmt.Errorf("error parsing yaml: %v", err)
		}
		group, ok := obj.(*kopsapi.InstanceGroup)
		if !ok {
			return fmt.Errorf("unexpected object type: %T", obj)
		}

		err = validation.CrossValidateInstanceGroup(group, cluster, cloud, true).ToAggregate()
		if err != nil {
			return err
		}

		ig = group
	}

	_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})
	if err != nil {
		return fmt.Errorf("error storing InstanceGroup: %v", err)
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the YAML syntax reported by the wrapped decoder error (check line/column in the message)
  2. Replace tab characters with spaces for indentation
  3. Re-run with --edit=false and edit the file with a proper YAML validator/linter (yamllint)
  4. Restore the original structure: keep apiVersion, kind: InstanceGroup, metadata, and spec intact
  5. Validate the YAML locally before saving, e.g. `python -c 'import yaml,sys; yaml.safe_load(sys.stdin)' < file`

Example fix

// before (in editor)
spec:
	machineType: n1-standard-1
// after
spec:
  machineType: n1-standard-1
Defensive patterns

Strategy: validation

Validate before calling

# validate the edited YAML before saving in the editor
yamllint ig.yaml || python3 -c 'import yaml,sys; yaml.safe_load(open("ig.yaml"))'

Try / catch

if err != nil && strings.Contains(err.Error(), "error parsing yaml") {
	// re-open editor or restore original template and re-edit carefully with spaces
}

Prevention

When it happens

Trigger: Editing the InstanceGroup YAML in the editor and introducing invalid YAML (bad indentation, tabs, stray characters), deleting required fields, or pasting non-YAML content into the buffer before saving.

Common situations: Editor converts indentation to tabs (YAML forbids tabs); smart-quote autocorrect from GUI editors; accidental truncation of the file; pasting JSON with syntax errors; editor saves a lockfile-suffixed or partial file.

Related errors


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