GoogleContainerTools/skaffold · warning
could not fetch deployed resource namespace. This might caus
Error message
could not fetch deployed resource namespace. This might cause port-forward and deploy health-check to fail: %w
What it means
After reading hydrated manifests, the kpt deployer collects the namespaces of the resources to be deployed. If CollectNamespaces fails, skaffold records this DeployInfoEvent warning that port-forwarding and deploy health checks may not work, since they depend on knowing resource namespaces. The deploy itself (kpt live apply) proceeds.
Source
Thrown at pkg/skaffold/deploy/kpt/kpt.go:337
manifests, err := k.getManifests(ctx)
if err != nil {
event.DeployInfoEvent(fmt.Errorf("could not read the hydrated manifest from %v: %w", k.applyDir, err))
}
endTrace()
// Add debug transformations
debugHelpersRegistry, err := config.GetDebugHelpersRegistry(k.globalConfig)
if err != nil {
return err
}
if manifests, err = manifest.ApplyTransforms(manifests, builds, k.insecureRegistries, debugHelpersRegistry); err != nil {
return err
}
_, endTrace = instrumentation.StartTrace(ctx, "Deploy_CollectNamespaces")
namespaces, err := manifests.CollectNamespaces()
if err != nil {
event.DeployInfoEvent(fmt.Errorf("could not fetch deployed resource namespace. "+
"This might cause port-forward and deploy health-check to fail: %w", err))
}
endTrace()
childCtx, endTrace := instrumentation.StartTrace(ctx, "Deploy_execKptCommand")
args := []string{"live", "apply", k.applyDir}
args = append(args, k.Flags...)
args = append(args, k.ApplyFlags...)
cmd := exec.CommandContext(childCtx, "kpt", args...)
cmd.Stdout = out
cmd.Stderr = out
if err := util.RunCmd(ctx, cmd); err != nil {
endTrace(instrumentation.TraceEndError(err))
return liveApplyErr(err, k.applyDir)
}
k.TrackBuildArtifacts(builds, builds)
k.trackNamespaces(namespaces)View on GitHub (pinned to a1189de023)
Solutions
- Set an explicit `namespace:` field on resources in the hydrated manifests.
- Pass `-n/--namespace` or set the kubectl context's default namespace (`kubectl config set-context --current --namespace=...`).
- Check the wrapped root cause in the event output and fix the offending manifest document.
- Ignore if port-forward/health-check are not used; the deploy continues.
Example fix
// before kind: Deployment metadata: name: app // after kind: Deployment metadata: name: app namespace: my-ns
Defensive patterns
Strategy: validation
Validate before calling
// Ensure every manifest declares a namespace before deploy
for _, doc := range docs {
if doc.Metadata.Namespace == "" {
return fmt.Errorf("resource %s/%s has no namespace", doc.APIVersion, doc.Kind)
}
} Try / catch
// Treat as non-fatal but degrade gracefully
if err := collectErr; err != nil {
log.Warnf("namespace collection failed, disabling port-forward: %v", err)
} Prevention
- Set metadata.namespace explicitly on all resources
- Configure a default namespace on the kube context
- Fix malformed manifests found in hydration output
- Don't rely on skaffold port-forward if namespace discovery is impossible
When it happens
Trigger: manifests.CollectNamespaces() errors during kpt Deploy — typically when manifests lack explicit namespaces and context is unset, or a manifest document is malformed/unparseable so its namespace cannot be extracted.
Common situations: Manifests relying on `namespace:` from kubectl context instead of specifying it; cluster-restricted namespace discovery; partially invalid hydrated YAML.
Related errors
- could not fetch deployed resource namespace. This might caus
- could not read the hydrated manifest from %v: %w
- resolving namespace: %w
- getting kubeconfig: %w
- getting k8s configuration: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/8df8872a01deb9fd.
Report an issue: GitHub.