GoogleContainerTools/skaffold · error · nsSettingErr
error converting %s to map[string]interface{}
Error message
error converting %s to map[string]interface{} What it means
Skaffold's addOrUpdateNamespace sets metadata.namespace on each Kubernetes manifest. Before writing the namespace field it asserts the manifest's `metadata` value is a map[string]interface{} (as produced by yaml.Unmarshal). If metadata holds any other Go type (string, number, list, bool), the conversion fails and this error is returned wrapped by nsSettingErr.
Source
Thrown at pkg/skaffold/kubernetes/manifest/namespaces.go:127
}
updated = append(updated, updatedManifest)
}
log.Entry(context.TODO()).Debugln("manifests set with namespace", updated.String())
return updated, nil
}
func addOrUpdateNamespace(manifest map[string]interface{}, ns string) error {
originalMetadata, ok := manifest[metadataField]
if !ok {
metadataAdded := make(map[string]interface{})
metadataAdded[namespaceField] = ns
manifest[metadataField] = metadataAdded
return nil
}
metadata, ok := originalMetadata.(map[string]interface{})
if !ok {
return nsSettingErr(fmt.Errorf("error converting %s to map[string]interface{}", originalMetadata))
}
nsValue, present := metadata[namespaceField]
if !present || isEmptyOrEqual(nsValue, ns) {
metadata[namespaceField] = ns
return nil
}
if present && isEmptyOrEqual(ns, defaultNamespace) {
return nil
}
warnings.Printf("a manifest already has namespace set \"%s\" which conflicts with namespace on the CLI \"%s\"", nsValue, ns)
return nil
}
func isEmptyOrEqual(v interface{}, s string) bool {
// check if namespace is set to empty string
if v == nil {View on GitHub (pinned to a1189de023)
Solutions
- Fix the manifest so `metadata:` is a mapping containing name/namespace fields
- Re-render the manifests (kustomize/helm) and verify with yamllint or `kubectl apply --dry-run=client` before running Skaffold
- If the document is not a real Kubernetes resource, exclude it from the manifest list passed to Skaffold
Example fix
# before metadata: prod kind: ConfigMap # after metadata: name: my-config namespace: prod kind: ConfigMap
Defensive patterns
Strategy: type-guard
Validate before calling
var check map[string]interface{}
if err := yaml.Unmarshal(manifestBytes, &m); err != nil { return err }
if md, ok := m["metadata"].(map[string]interface{}); !ok && m["metadata"] != nil {
return fmt.Errorf("metadata must be a mapping, got %T", m["metadata"])
} Type guard
func isMetadataMap(m map[string]interface{}) bool {
if md, ok := m["metadata"]; ok {
_, ok := md.(map[string]interface{})
return ok
}
return true
} Prevention
- Lint manifests with yamllint/kubeconform before feeding them to Skaffold
- Keep `metadata:` always a mapping in generated YAML
- Dry-run render output with kubectl before running namespace transforms
When it happens
Trigger: Calling SetNamespace (directly or via namespace-transform of a ManifestList) on a manifest whose top-level `metadata:` key parses to a non-map YAML scalar or sequence, e.g. `metadata: my-ns` or `metadata: [a, b]`.
Common situations: Hand-written or generated YAML where metadata is accidentally a scalar; templating tools emitting malformed manifests; manifests with duplicate/odd keys parsed into unexpected types.
Related errors
- STATUSCHECK_CONFIG_CONNECTOR_RESOURCES_FETCH_ERR
- could not fetch config connector resources: %w
- could not fetch custom resources: %w
- invalid local-registry-hosting ConfigMap
- loading post-renderer result: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/95c0b57036f369f3.
Report an issue: GitHub.