fix: helmfile fetch fails for kustomization directories (#2504)

* fix: helmfile fetch fails for kustomization directories

Fixes #2503

When running `helmfile fetch` on a release that points to a local
kustomization directory (without Chart.yaml), the command failed with
"Chart.yaml is missing".

The issue was that the condition `helmfileCommand != "pull"` in
prepareChartForRelease skipped chartification for ALL cases during
fetch, including local kustomization directories that NEED chartify
to convert them to Helm charts.

Solution:
- Added `NeedsChartifyForLocalDir` field to the Chartify struct to
  track when chartification is needed because the local directory
  is not a Helm chart (no Chart.yaml)
- Modified the condition to skip chartification for "pull" ONLY when
  it's not a local directory without Chart.yaml

This preserves the original fix (commit 1f134d93) for remote charts
with transformers while fixing local kustomization directories.

Signed-off-by: yxxhero <aiopsclub@163.com>

* test: add integration test for helmfile fetch with kustomization

Add test case for issue #2503 to verify helmfile fetch works correctly
with local kustomization directories (without Chart.yaml).

Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2026-03-26 09:44:28 +08:00
committed by GitHub
parent 2053fdd94e
commit 732e4ad913
7 changed files with 34 additions and 3 deletions
+4 -2
View File
@@ -303,8 +303,9 @@ func (st *HelmState) appendShowOnlyFlags(flags []string, showOnly []string) []st
}
type Chartify struct {
Opts *chartify.ChartifyOpts
Clean func()
Opts *chartify.ChartifyOpts
Clean func()
NeedsChartifyForLocalDir bool
}
func (st *HelmState) downloadChartWithGoGetter(r *ReleaseSpec) (string, error) {
@@ -375,6 +376,7 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
if stat, _ := os.Stat(dir); stat != nil && stat.IsDir() {
if exists, err := st.fs.FileExists(filepath.Join(dir, "Chart.yaml")); err == nil && !exists {
shouldRun = true
c.NeedsChartifyForLocalDir = true
}
}
+1 -1
View File
@@ -1764,7 +1764,7 @@ func (st *HelmState) prepareChartForRelease(release *ReleaseSpec, helm helmexec.
skipRefreshDefault := release.SkipRefresh == nil && st.HelmDefaults.SkipRefresh
skipRefresh := !isLocal || skipRefreshGlobal || skipRefreshRelease || skipRefreshDefault
if chartification != nil && helmfileCommand != "pull" {
if chartification != nil && (helmfileCommand != "pull" || chartification.NeedsChartifyForLocalDir) {
// Issue #2297: Normalize local chart paths before chartification
// When using transformers with local charts like "../chart", the chartify process
// needs an absolute path, otherwise it tries "helm pull ../chart" which fails