fix: pre-build transitive subchart deps for envelope charts (#851)

Helm's `dependency build` on the parent chart fetches each file:// subchart
and packages it as .tgz, but does NOT recursively build the subchart's own
dependencies first. For envelope charts whose subcharts declare their own
local file:// dependencies, the resulting .tgz lacks the nested subchart's
resources. chartify's `helm template` then silently drops those resources,
and strategicMergePatches/jsonPatches targeting them fail with
"no resource matches".

Fix: add `preBuildTransitiveSubchartDeps`, called from processChartification
before chartify runs (gated on !skipDeps). It walks the transitive file://
dependency tree depth-first and runs `helm dependency build` bottom-up on each
subchart source directory, so each subchart's deps are pre-built before the
parent packages them. The function is best-effort: errors are logged at debug
level and do not abort the operation, matching helmfile's existing behavior
of tolerating already-built deps.

Verified with a reproduction case that fails before the fix
(`Error: no resource matches strategic merge patch ".../nested-sm.[noNs]"`)
and passes after it.

Resolves #851

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2026-07-02 06:37:50 +08:00
committed by yxxhero
parent cc85562625
commit 08504ad6f6
14 changed files with 559 additions and 0 deletions
+18
View File
@@ -285,6 +285,24 @@ There's also `releases[].jsonPatches` that works similarly to `strategicMergePat
Please also see [test/advanced/helmfile.yaml](https://github.com/helmfile/helmfile/tree/master/test/advanced/helmfile.yaml) for an example of patching support and more.
#### Patching envelope charts (charts whose subcharts have local dependencies)
`strategicMergePatches`, `jsonPatches`, and `transformers` all work on resources defined
anywhere in the chart, including resources rendered by transitive subcharts (a subchart's
own dependencies).
For local envelope charts whose subcharts declare their own `file://` dependencies, Helmfile
runs `helm dependency build` bottom-up across the transitive dependency tree before chartify
runs. Without this, helm's `dependency build` on the parent chart would fetch each file://
subchart and package it as a `.tgz` **without** recursively building the subchart's own deps
first. The resulting `.tgz` would lack the nested subchart's resources, chartify's
`helm template` would silently drop them, and patches targeting those resources would fail
with `no resource matches`.
See [issue #851](https://github.com/helmfile/helmfile/issues/851).
To opt out of dependency building (e.g. for read-only `template` invocations), use
`--skip-deps` or set `helmDefaults.skipDeps: true` / `releases[].skipDeps: true`.
### `transformers`
You can set `transformers` to apply [Kustomize's transformers](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/configureBuiltinPlugin.md#configuring-the-builtin-plugins-instead).