kubernetes/kops · error
error parsing yaml: %v
Error message
error parsing yaml: %v
What it means
LoadObjectsFrom splits a manifest file into YAML documents and unmarshals each section into a generic map. When a section is not valid YAML (or is not a mapping), it logs the offending section via klog and returns this error, aborting the load.
Source
Thrown at pkg/kubemanifest/manifest.go:81
type ObjectList []*Object
// LoadObjectsFrom parses multiple objects from a yaml file
func LoadObjectsFrom(contents []byte) (ObjectList, error) {
var objects []*Object
sections := text.SplitContentToSections(contents)
for _, section := range sections {
// We need this so we don't error on a section that is empty / commented out
if !hasYAMLContent(section) {
continue
}
data := make(map[string]interface{})
err := yaml.Unmarshal(section, &data)
if err != nil {
klog.Infof("invalid YAML section: %s", string(section))
return nil, fmt.Errorf("error parsing yaml: %v", err)
}
obj := &Object{
// bytes: section,
data: data,
}
objects = append(objects, obj)
}
return objects, nil
}
// hasYAMLContent determines if the byte slice has any content,
// because yaml parsing gives an error if called with no content.
// TODO: How does apimachinery avoid this problem?
func hasYAMLContent(yamlData []byte) bool {
for _, line := range bytes.Split(yamlData, []byte("\n")) {
l := bytes.TrimSpace(line)View on GitHub (pinned to 4c8573c808)
Solutions
- Fix the YAML syntax in the flagged section (the invalid section is printed just above the error in klog output)
- Run `yamllint` or `kubectl apply --dry-run=client -f file.yaml` to pinpoint the line
- Replace tabs with spaces and fix indentation/duplicate keys
- Re-download/restore the manifest file if it was truncated or corrupted
Example fix
// before (manifest.yaml) addons: - name: foo # tab indentation -> parse error // after addons: - name: foo
Defensive patterns
Strategy: validation
Validate before calling
func validateYAMLFile(path string) error {
data, err := os.ReadFile(path)
if err != nil { return err }
for i, section := range bytes.Split(data, []byte("\n---")) {
var m map[string]interface{}
if err := yaml.Unmarshal(section, &m); err != nil {
return fmt.Errorf("document %d invalid: %w", i, err)
}
}
return nil
}
Try / catch
objs, err := kubemanifest.LoadObjectsFrom(data)
if err != nil {
if strings.Contains(err.Error(), "error parsing yaml") {
return fmt.Errorf("manifest file is not valid YAML; run yamllint on it: %w", err)
}
return err
}
Prevention
- Lint manifests with yamllint before use
- Use spaces, never tabs, in YAML
- Check for truncated downloads (file size, checksum)
- Validate with `kubectl apply --dry-run=client -f`
When it happens
Trigger: Calling any of LoadObjectsFrom's callers (ParseAddons, Apply, Prune, List, RemapManifest, ParseClusterAddon) with a file containing malformed YAML syntax, tabs for indentation, or a document that unmarshals to a non-map value.
Common situations: Hand-edited addon manifests with indentation mistakes; tabs instead of spaces; duplicate keys; truncated files from failed downloads; passing a non-manifest file to the command.
Related errors
- error parsing addons or manifest: %v
- failed to parse objects: %w
- failed to parse objects: %w
- parsing yaml: %w
- error parsing addon %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/7098b6f788d3a48a.
Report an issue: GitHub.