GoogleContainerTools/skaffold · error

reading Kubernetes YAML: %w

Error message

reading Kubernetes YAML: %w

What it means

A YAML document was read successfully but yaml.Unmarshal into the generic yamlObject map failed, wrapped as 'reading Kubernetes YAML: %w'. This means the document is syntactically invalid YAML or has a structure that cannot decode into a map (e.g. a top-level list or scalar).

Source

Thrown at pkg/skaffold/kubernetes/util.go:103

	}
	defer f.Close()

	r := k8syaml.NewYAMLReader(bufio.NewReader(f))

	var k8sObjects []yamlObject

	for {
		doc, err := r.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			return nil, fmt.Errorf("reading config file: %w", err)
		}

		obj := make(yamlObject)
		if err := yaml.Unmarshal(doc, &obj); err != nil {
			return nil, fmt.Errorf("reading Kubernetes YAML: %w", err)
		}

		if !hasRequiredK8sManifestFields(obj) {
			continue
		}

		k8sObjects = append(k8sObjects, obj)
	}
	if len(k8sObjects) == 0 {
		return nil, errors.New("no valid Kubernetes objects decoded")
	}
	return k8sObjects, nil
}

func hasRequiredK8sManifestFields(doc map[string]interface{}) bool {
	for _, field := range requiredFields {
		if _, ok := doc[field]; !ok {
			log.Entry(context.TODO()).Debugf("%s not present in yaml, continuing", field)

View on GitHub (pinned to a1189de023)

Solutions

  1. Validate the YAML: `yamllint <file>` or `kubectl apply --dry-run=client -f <file>` to see the exact line/column
  2. Replace tabs with spaces and fix indentation at the reported line
  3. Ensure every document in the file starts with a mapping (key: value), not a list or scalar
  4. Quote values containing special characters (':', '{', '}', '#', '@')

Example fix

// before
containers:
	- name: app
// after
containers:
  - name: app
Defensive patterns

Strategy: validation

Validate before calling

// lint YAML before handing it to skaffold
func lintYAML(path string) error {
    data, err := os.ReadFile(path)
    if err != nil {
        return err
    }
    for i, doc := range strings.Split(string(data), "\n---") {
        var m map[string]interface{}
        if err := yaml.Unmarshal([]byte(doc), &m); err != nil {
            return fmt.Errorf("%s doc %d: %w", path, i, err)
        }
    }
    return nil
}

Try / catch

if _, err := kubernetes.ParseKubernetesObjects(path); err != nil {
    var yamlErr *yaml.TypeError
    if errors.As(err, &yamlErr) || strings.Contains(err.Error(), "reading Kubernetes YAML") {
        return fmt.Errorf("invalid YAML in %s, run yamllint: %w", path, err)
    }
    return err
}

Prevention

When it happens

Trigger: A manifest file contains malformed YAML (bad indentation, tabs, duplicate keys with strict decoding, stray characters) or a document whose root is not a mapping, passed to ParseKubernetesObjects via validateManifests/IsKubernetesManifest/ParseImagesFromKubernetesYaml.

Common situations: Hand-edited manifests with tab indentation; copied YAML that lost indentation; a multi-doc file where one doc is `--- [1,2,3]`; unescaped special characters like ':' or '@' in values.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/689785c7502d91ba. Report an issue: GitHub.