GoogleContainerTools / GoogleContainerTools/skaffold

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

Open Beginner friendly
#10,126 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
15.9k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

## 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="]
--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`:

```yaml
apiVersion: skaffold/v4beta14
kind: Config
metadata:
name: myapp
build:
artifacts:
- image: myapp
docker:
dockerfile: Dockerfile
manifests:
rawYaml:
- k8s/*.yaml
deploy:
kubectl:
defaultNamespace: "myapp-{{.environment}}"
```

```shell
# 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 `` (e.g. when the underlying env var isn't set), so this does not change behavior for configs that aren't using templated fields.

Contributor guide

Open the contributing guide

Research direction

Start in cmd/skaffold/app/cmd/diagnose.go and inspect how the --enable-templating default is defined. Reproduce the behavior with the provided skaffold diagnose commands and an environment-backed template, then verify that templated fields expand by default while explicitly disabling templating preserves the opt-out behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, google-cloud
Domain
cli, cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.