Description
Google Cloud Deploy's render phase generates the canonical config.yaml for a release internally via skaffold diagnose, but invokes it without --enable-templating=true. As a result, any Skaffold config field that supports Go-template interpolation (tagged skaffold:"...,template", e.g. deploy.kubectl.defaultNamespace) is left as a literal, unexpanded template string instead of being populated from the deploy parameters / environment variables that Cloud Deploy injects for the release.
This further cascades into downstream steps — e.g. the verify job — that rely on the resolved deploy.kubectl.defaultNamespace.
Relevant log (Cloud Deploy render phase, trimmed to the relevant skaffold invocations)
Running the following command: skaffold [render --filename=/workspace/stable/config.yaml --build-artifacts=/workspace/artifacts.json --output=/workspace/stable/manifest.yaml --offline=true --digest-source=none --set="environment=pr-88" --set="git_sha=<redacted>"]
--digest-source set to 'none', tags listed in Kubernetes manifests will be used for render
Running the following command: skaffold [inspect namespaces list /workspace/stable/manifest.yaml --filename=/workspace/stable/config.yaml]
{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"myapp-gke","namespace":"myapp-gke-{{.environment}}"}]}}
Note "namespace":"myapp-gke-{{.environment}}" — the environment deploy parameter (pr-88 in this release) was never substituted into the template, because /workspace/stable/config.yaml (the effective config Cloud Deploy generated via skaffold diagnose) was produced without --enable-templating.
Root cause
skaffold diagnose --enable-templating defaults to false (cmd/skaffold/app/cmd/diagnose.go). Cloud Deploy never passes --enable-templating=true when it calls diagnose to produce its internal config.yaml, so fields tagged skaffold:"...,template" are never expanded.
Reproduction
Minimal skaffold.yaml that templates deploy.kubectl.defaultNamespace from a deploy parameter named environment:
apiVersion: skaffold/v4beta14
kind: Config
metadata:
name: myapp
build:
artifacts:
- image: myapp
docker:
dockerfile: Dockerfile
manifests:
rawYaml:
- k8s/*.yaml
deploy:
kubectl:
defaultNamespace: "myapp-{{.environment}}"
# simulates how Cloud Deploy invokes diagnose internally (deploy parameter as env var, no --enable-templating)
$ environment=pr-88 skaffold diagnose --yaml-only -f skaffold.yaml
...
deploy:
kubectl:
defaultNamespace: myapp-{{.environment}} # BUG: not interpolated
# manual workaround, passing the flag explicitly
$ environment=pr-88 skaffold diagnose --yaml-only -f skaffold.yaml --enable-templating
...
deploy:
kubectl:
defaultNamespace: myapp-pr-88 # expected
Expected behavior
Deploy parameters supplied as environment variables (as Google Cloud Deploy does) should be interpolated into templated fields by default, without requiring Cloud Deploy (or any other caller of diagnose) to explicitly pass --enable-templating=true.
Proposed fix
Default --enable-templating to true on skaffold diagnose. Templating is opt-out (--enable-templating=false) rather than opt-in, and expandTemplate already leaves a field untouched if expansion produces <no value> (e.g. when the underlying env var isn't set), so this does not change behavior for configs that aren't using templated fields.
Description
Google Cloud Deploy's render phase generates the canonical
config.yamlfor a release internally viaskaffold diagnose, but invokes it without--enable-templating=true. As a result, any Skaffold config field that supports Go-template interpolation (taggedskaffold:"...,template", e.g.deploy.kubectl.defaultNamespace) is left as a literal, unexpanded template string instead of being populated from the deploy parameters / environment variables that Cloud Deploy injects for the release.This further cascades into downstream steps — e.g. the
verifyjob — that rely on the resolveddeploy.kubectl.defaultNamespace.Relevant log (Cloud Deploy render phase, trimmed to the relevant
skaffoldinvocations)Note
"namespace":"myapp-gke-{{.environment}}"— theenvironmentdeploy parameter (pr-88in this release) was never substituted into the template, because/workspace/stable/config.yaml(the effective config Cloud Deploy generated viaskaffold diagnose) was produced without--enable-templating.Root cause
skaffold diagnose --enable-templatingdefaults tofalse(cmd/skaffold/app/cmd/diagnose.go). Cloud Deploy never passes--enable-templating=truewhen it callsdiagnoseto produce its internalconfig.yaml, so fields taggedskaffold:"...,template"are never expanded.Reproduction
Minimal
skaffold.yamlthat templatesdeploy.kubectl.defaultNamespacefrom a deploy parameter namedenvironment:Expected behavior
Deploy parameters supplied as environment variables (as Google Cloud Deploy does) should be interpolated into templated fields by default, without requiring Cloud Deploy (or any other caller of
diagnose) to explicitly pass--enable-templating=true.Proposed fix
Default
--enable-templatingtotrueonskaffold diagnose. Templating is opt-out (--enable-templating=false) rather than opt-in, andexpandTemplatealready leaves a field untouched if expansion produces<no value>(e.g. when the underlying env var isn't set), so this does not change behavior for configs that aren't using templated fields.