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
- 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
- Restore the header comments: apiVersion: kops.k8s.io/v1alpha2 and kind: InstanceGroup plus metadata.name
- Validate offline first: run the edited content through `kops get instancegroups -o yaml` round-trip or yamlfmt
- 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
- Never delete the header comments carrying apiVersion/kind in the edit buffer
- Use spaces, never tabs, in YAML
- Lint the file with a YAML parser before saving
- Round-trip with `kops get instancegroup <name> -o yaml` to see the canonical shape
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
- error parsing file %q: %v
- error parsing yaml: %v
- unable decode the configuration file: %s, error: %v
- error parsing addons or manifest: %v
- error parsing addons: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/df020880eac5acef.
Report an issue: GitHub.