{"record":{"id":"00a7ee459c29e89d","repo":"GoogleContainerTools/skaffold","slug":"cannot-parse-the-namespace-template-on-user-define","errorCode":null,"errorMessage":"cannot parse the namespace template on user defined port forwarder: %w","messagePattern":"cannot parse the namespace template on user defined port forwarder: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/portforward/resource_forwarder.go","lineNumber":115,"sourceCode":"\t}\n\n\tvar serviceResources []*latest.PortForwardResource\n\tif p.services {\n\t\tfound, err := retrieveServices(ctx, p.label, namespaces, p.kubeContext)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"retrieving services for automatic port forwarding: %w\", err)\n\t\t}\n\t\tserviceResources = found\n\t}\n\tp.portForwardResources(ctx, append(p.userDefinedResources, serviceResources...))\n\treturn nil\n}\n\nfunc applyWithTemplate(resource *latest.PortForwardResource) error {\n\tif resource.Namespace != \"\" {\n\t\tnamespace, err := util.ExpandEnvTemplateOrFail(resource.Namespace, nil)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot parse the namespace template on user defined port forwarder: %w\", err)\n\t\t}\n\t\tresource.Namespace = namespace\n\t}\n\tname, err := util.ExpandEnvTemplateOrFail(resource.Name, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse the name template on user defined port forwarder: %w\", err)\n\t}\n\tresource.Name = name\n\treturn nil\n}\n\nfunc (p *ResourceForwarder) Stop() {\n\tp.entryManager.Stop()\n}\n\n// Port forward each resource individually in a goroutine\nfunc (p *ResourceForwarder) portForwardResources(ctx context.Context, resources []*latest.PortForwardResource) {\n\tvar wg sync.WaitGroup","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/portforward/resource_forwarder.go#L97-L133","documentation":"applyWithTemplate expands environment-variable templates in user-defined port-forward resources. If the namespace field contains an invalid template (e.g. unbalanced braces or a missing env var), ExpandEnvTemplateOrFail fails and the error is wrapped with \"cannot parse the namespace template on user defined port forwarder\".","triggerScenarios":"PortForwardResource.Namespace is non-empty and util.ExpandEnvTemplateOrFail(resource.Namespace, nil) errors during Start's resource preparation — caused by malformed Go template syntax or an undefined environment variable in skaffold.yaml's portForward.namespace.","commonSituations":"skaffold.yaml has portForward namespace like {{.MISSING_VAR}} or {{NAMESPACE} (unbalanced brace); CI environment lacks a variable set locally; copy-pasted template using wrong delimiters.","solutions":["Fix the template syntax in the portForward namespace field (balanced {{ }} and valid field names)","Define the referenced environment variable in the shell/CI before running skaffold","Use a literal namespace string instead of a template if templating is unnecessary","Validate the config with skaffold config or skaffold dev --dry-run style checks before deploy"],"exampleFix":"# before (skaffold.yaml)\nportForward:\n  - resourceType: pod\n    resourceName: web\n    namespace: {{.MISSING_NS}}\n# after\nexport NAMESPACE=my-ns  # or fix the template\nportForward:\n  - resourceType: pod\n    resourceName: web\n    namespace: {{.NAMESPACE}}","handlingStrategy":"validation","validationCode":"func validNamespaceTemplate(ns string) error {\n    if ns == \"\" {\n        return nil\n    }\n    if strings.Count(ns, \"{{\") != strings.Count(ns, \"}}\") {\n        return fmt.Errorf(\"unbalanced template braces in namespace %q\", ns)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := applyWithTemplate(res); err != nil {\n    if strings.Contains(err.Error(), \"namespace template\") {\n        return fmt.Errorf(\"fix portForward.namespace in skaffold.yaml: %v\", err)\n    }\n    return err\n}","preventionTips":["Use balanced {{ }} Go template syntax in skaffold.yaml portForward fields","Export every env var referenced by templates before running skaffold","Prefer literal namespace values unless templating is required"],"tags":["config","template","port-forward"],"backgroundTag":"template-parse-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}