kubernetes/kops · error

error parsing InstanceGroup: %v

Error message

error parsing InstanceGroup: %v

What it means

After the editor closes, kops decodes the edited buffer with kopscodecs.Decode into a typed object. Any YAML/JSON syntax error, unknown field, wrong kind, or missing apiVersion/kind produces "error parsing InstanceGroup". The temp file is preserved so the bad content is not lost.

Source

Thrown at cmd/kops/edit_instancegroup.go:229

		if bytes.Equal(stripComments(raw), stripComments(edited)) {
			try.RemoveFile(file)
			fmt.Fprintln(out, "Edit cancelled: no changes made.")
			return nil
		}

		lines, err := hasLines(bytes.NewBuffer(edited))
		if err != nil {
			return preservedFile(err, file, out)
		}
		if !lines {
			try.RemoveFile(file)
			fmt.Fprintln(out, "Edit cancelled: saved file was empty.")
			return nil
		}

		newObj, _, err := kopscodecs.Decode(edited, nil)
		if err != nil {
			return preservedFile(fmt.Errorf("error parsing InstanceGroup: %v", err), file, out)
		}

		newGroup, ok := newObj.(*api.InstanceGroup)
		if !ok {
			results = editResults{
				file: file,
			}
			results.header.addError(fmt.Sprintf("object was not of expected type: %T", newObj))
			containsError = true
			continue
		}

		extraFields, err := edit.HasExtraFields(string(edited))
		if err != nil {
			results = editResults{
				file: file,
			}
			results.header.addError(fmt.Sprintf("error checking for extra fields: %v", err))

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the syntax/structure error reported in the wrapped %v (line/column is usually included); the preserved file path is printed — reopen and fix it
  2. Restore the header comments: apiVersion: kops.k8s.io/v1alpha2 and kind: InstanceGroup plus metadata.name
  3. Validate offline first: run the edited content through `kops get instancegroups -o yaml` round-trip or yamlfmt
  4. Paste the file into a YAML linter to find indentation/tab issues

Example fix

// before (broken)
metadata:
  name: nodes
spec:
 machineType: t3.medium  # bad indent
// after
metadata:
  name: nodes
spec:
  machineType: t3.medium
Defensive patterns

Strategy: validation

Validate before calling

func validInstanceGroupYAML(b []byte) error {
    var m map[string]interface{}
    if err := yaml.Unmarshal(b, &m); err != nil {
        return fmt.Errorf("invalid YAML: %w", err)
    }
    if m["kind"] != "InstanceGroup" || m["apiVersion"] != "kops.k8s.io/v1alpha2" {
        return errors.New("missing kind: InstanceGroup / apiVersion header")
    }
    return nil
}

Type guard

obj, _, err := kopscodecs.Decode(edited, nil)
ig, ok := obj.(*api.InstanceGroup)
if !ok || err != nil {
    return fmt.Errorf("not a valid InstanceGroup: %v", err)
}

Try / catch

if err := runEdit(); err != nil {
    var perr *yaml.TypeError
    if errors.As(err, &perr) || strings.Contains(err.Error(), "error parsing InstanceGroup") {
        // reopen the preserved temp file and fix the reported line/column
    }
}

Prevention

When it happens

Trigger: Saving `kops edit instancegroup` output with malformed YAML (bad indentation, tabs, duplicate keys), a stripped apiVersion: kops.k8s.io/v1alpha2 / kind: InstanceGroup header, or a field that fails schema deserialization.

Common situations: Manual edits breaking YAML indentation; editor inserting tabs; accidentally deleting the header comments containing kind/apiVersion; pasting a Cluster manifest instead of an InstanceGroup.

Related errors


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