GoogleContainerTools/skaffold · error
reading Kubernetes YAML: %w
Error message
reading Kubernetes YAML: %w
What it means
SetNamespace unmarshals each manifest item into a generic map (map[string]interface{}) with gopkg.in/yaml.v3 before conditionally adding the namespace. If a manifest is not valid YAML, yaml.Unmarshal fails and the error is wrapped as 'reading Kubernetes YAML'.
Source
Thrown at pkg/skaffold/kubernetes/manifest/namespaces.go:98
if ns := strings.TrimSpace(nsString); ns != "" {
r.namespaces[ns] = true
}
}
return false
}
// SetNamespace sets labels to a list of Kubernetes manifests if they are not set.
// Returns error if any manifest in the list has namespace set.
func (l *ManifestList) SetNamespace(namespace string, rs ResourceSelector) (ManifestList, error) {
if namespace == "" {
namespace = defaultNamespace
}
var updated ManifestList
for _, item := range *l {
updatedManifest := item
m := make(map[string]interface{})
if err := yaml.Unmarshal(item, &m); err != nil {
return nil, fmt.Errorf("reading Kubernetes YAML: %w", err)
}
if shouldTransformManifest(m, rs) {
var errU error
if errU = addOrUpdateNamespace(m, namespace); errU != nil {
return nil, errU
}
updatedManifest, errU = yaml.Marshal(m)
if errU != nil {
return nil, nsSettingErr(errU)
}
}
updated = append(updated, updatedManifest)
}
log.Entry(context.TODO()).Debugln("manifests set with namespace", updated.String())
return updated, nil
}
View on GitHub (pinned to a1189de023)
Solutions
- Fix the YAML syntax error named in the wrapped cause (yaml.v3 reports line/column)
- Ensure each document is a top-level mapping (object), not a list or scalar
- Run a YAML parser/linter over each manifest to catch the offending file before transformation
- Regenerate the manifest list from the render step and confirm its output parses
Example fix
// before: top-level list cannot unmarshal into map[string]interface{}
- apiVersion: v1
kind: Service
// after
apiVersion: v1
kind: Service Defensive patterns
Strategy: validation
Validate before calling
import "gopkg.in/yaml.v3"
func isYAMLMap(item []byte) error {
var m map[string]interface{}
if err := yaml.Unmarshal(item, &m); err != nil { return err }
if m == nil { return errors.New("empty or non-mapping document") }
return nil
}
// check each item before SetNamespace Type guard
func isDocMapping(item []byte) bool {
var m map[string]interface{}
return yaml.Unmarshal(item, &m) == nil && m != nil
} Try / catch
updated, err := manifests.Transform(rs, transform.SetNamespace(ns))
if err != nil && strings.Contains(err.Error(), "reading Kubernetes YAML") {
// find the malformed item, fix or drop it, then retry the transform
return fmt.Errorf("manifest unreadable as YAML: %w", err)
} Prevention
- Ensure each manifest item is a top-level YAML mapping before transforms
- Lint manifests (yamllint) in pre-commit and CI
- Avoid tabs and duplicate keys in manifest sources
- Dry-run renders with 'skaffold render' to catch unreadable manifests early
When it happens
Trigger: Calling ManifestList.SetNamespace (via BaseTransform) when any item in the ManifestList is malformed YAML — syntax errors, or content that cannot unmarshal into a map (e.g. a top-level sequence or scalar).
Common situations: Templates or Helm output producing invalid YAML, manifests whose top level is a list instead of an object, files with duplicate keys or bad types (e.g. 'replicas: abc' where the map decode is fine but downstream steps then fail).
Related errors
- yaml to json error: %w
- loading post-renderer result: %w
- loading manifests: %w
- DEPLOY_READ_MANIFEST_ERR
- parsing manifests file into manifest list object: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/a998a9ea38cd5f0e.
Report an issue: GitHub.