GoogleContainerTools/skaffold · error

collecting namespaces: %w

Error message

collecting namespaces: %w

What it means

CollectNamespaces runs ManifestList.Visit with a ResourceSelectorImages visitor to gather the namespaces declared across all manifests. Any error surfacing from Visit (YAML/JSON decode failure, unmarshaling error, affinity error, etc.) is wrapped as 'collecting namespaces'.

Source

Thrown at pkg/skaffold/kubernetes/manifest/namespaces.go:45

	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/warnings"
	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/yaml"
)

const namespaceField = "namespace"

const defaultNamespace = "default"

// CollectNamespaces returns all the namespaces in the manifests.
func (l *ManifestList) CollectNamespaces() ([]string, error) {
	replacer := newNamespaceCollector()

	// TODO(aaron-prindle) make sure this is ok?
	rs := &ResourceSelectorImages{}
	if _, err := l.Visit(replacer, rs); err != nil {
		// if _, err := l.Visit(replacer, make(map[schema.GroupKind]latest.ResourceFilter), make(map[schema.GroupKind]latest.ResourceFilter)); err != nil {
		// TODO(aaron-prindle) verify this doesn't need to support allow/deny list, also see if 'nil' is better option for unused inputs
		return nil, fmt.Errorf("collecting namespaces: %w", err)
	}

	namespaces := make([]string, 0, len(replacer.namespaces))
	for ns := range replacer.namespaces {
		namespaces = append(namespaces, ns)
	}
	sort.Strings(namespaces)
	return namespaces, nil
}

type namespaceCollector struct {
	namespaces map[string]bool
}

func newNamespaceCollector() *namespaceCollector {
	return &namespaceCollector{
		namespaces: map[string]bool{},
	}

View on GitHub (pinned to a1189de023)

Solutions

  1. Inspect the wrapped cause (%w) — it names the underlying manifest error; fix that document first
  2. Validate all manifests with 'kubectl apply --dry-run=client' or yamllint before rendering/deploying
  3. Fix the invalid YAML/JSON in the offending manifest (tabs, bad indentation, non-mapping documents)
  4. Regenerate the manifest list from source if it was corrupted by a pipeline step

Example fix

// before: tabs break YAML parsing inside Visit
spec:
	replicas: 1
// after
spec:
  replicas: 1
Defensive patterns

Strategy: try-catch

Validate before calling

import "gopkg.in/yaml.v3"
func validateAll(manifests [][]byte) error {
  for _, m := range manifests {
    var v interface{}
    if err := yaml.Unmarshal(m, &v); err != nil { return fmt.Errorf("invalid manifest %q: %w", m, err) }
  }
  return nil
}
// run before CollectNamespaces

Try / catch

ns, err := manifests.CollectNamespaces()
if err != nil {
  if strings.Contains(err.Error(), "collecting namespaces") {
    // the wrapped cause identifies the bad manifest; log it and abort or skip
    return fmt.Errorf("manifest set invalid, cannot collect namespaces: %w", err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling ManifestList.CollectNamespaces (directly or via getObjectNamespaceIfDefined) when the underlying Visit fails — typically because a manifest in the list is invalid YAML or not a decodable Kubernetes object.

Common situations: Broken manifests produced by an upstream render step propagating as a namespace-collection failure; manifests referencing malformed CRDs or empty documents.

Related errors


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