kubernetes/kops · error
unable to marshal YAML: %v
Error message
unable to marshal YAML: %v
What it means
This error is raised when yaml.Marshal(result) fails while rendering validation results in --output yaml mode. yaml.Marshal of a plain validation result struct essentially never fails in practice; failure implies an unmarshalable type in the result (e.g. channel, func field) or a corrupted result produced by the validator.
Source
Thrown at cmd/kops/validate_cluster.go:213
consecutive = 0
if options.wait > 0 {
klog.Warningf("(will retry): unexpected error during validation: %v", err)
time.Sleep(options.interval)
continue
} else {
return nil, fmt.Errorf("unexpected error during validation: %v", err)
}
}
switch options.output {
case OutputTable:
if err := validateClusterOutputTable(result, cluster, instanceGroups, out); err != nil {
return nil, err
}
case OutputYaml:
y, err := yaml.Marshal(result)
if err != nil {
return nil, fmt.Errorf("unable to marshal YAML: %v", err)
}
if _, err := out.Write(y); err != nil {
return nil, fmt.Errorf("error writing to output: %v", err)
}
case OutputJSON:
j, err := json.Marshal(result)
if err != nil {
return nil, fmt.Errorf("unable to marshal JSON: %v", err)
}
if _, err := out.Write(j); err != nil {
return nil, fmt.Errorf("error writing to output: %v", err)
}
default:
return nil, fmt.Errorf("unknown output format: %q", options.output)
}
if len(result.Failures) == 0 {
consecutive++View on GitHub (pinned to 4c8573c808)
Solutions
- Re-run with default table output or -o json to get results and file a bug if only yaml fails.
- Confirm kops binary version matches the cluster's kops version; upgrade or rebuild the binary.
- Check for locally patched kops builds or plugins altering the validation result type.
- Report to kops maintainers with the printed %v cause if it persists with official binaries.
Example fix
// before kops validate cluster -o yaml // after kops validate cluster -o json
Defensive patterns
Strategy: try-catch
Try / catch
result, err := runValidateCluster(ctx, options)
if err != nil && strings.Contains(err.Error(), "unable to marshal YAML") {
// fall back to JSON or table output
return runValidateCluster(ctx, withOutput(options, OutputJSON))
} Prevention
- Prefer -o json; YAML marshalling of validation results is a rarer path.
- Avoid patched kops builds that alter the result struct.
- Report reproducible marshal failures upstream as kops bugs.
- Pin kops version to the release matching your cluster.
When it happens
Trigger: `kops validate cluster -o yaml` where the validation result struct contains a value the YAML encoder cannot serialize.
Common situations: A kops version mismatch or patched binary injecting an unsupported field into the result struct; a custom validator plugin returning unserializable data; extremely rare — usually indicates a kops bug.
Related errors
- error converting to yaml: %v
- marshaling to yaml for %v: %w
- error marshaling manifest to yaml: %v
- error serializing addons yaml: %v
- error serializing addons: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/021ca3d9b4368524.
Report an issue: GitHub.