Skip to content

diagnose: --enable-templating defaults to false, breaking Cloud Deploy deploy-parameter interpolation #10126

Description

@bogdannazarenko

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions