From 732e4ad9134ef99b40d29b599a61e017ebcaaf3b Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Thu, 26 Mar 2026 09:44:28 +0800 Subject: [PATCH] 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 * 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 --------- Signed-off-by: yxxhero --- pkg/state/helmx.go | 6 ++++-- pkg/state/state.go | 2 +- test/integration/run.sh | 1 + .../test-cases/issue-2503-kustomize-fetch.sh | 14 ++++++++++++++ .../issue-2503-kustomize-fetch/input/helmfile.yaml | 3 +++ .../input/kustomize/configmap.yaml | 6 ++++++ .../input/kustomize/kustomization.yaml | 5 +++++ 7 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 test/integration/test-cases/issue-2503-kustomize-fetch.sh create mode 100644 test/integration/test-cases/issue-2503-kustomize-fetch/input/helmfile.yaml create mode 100644 test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/configmap.yaml create mode 100644 test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/kustomization.yaml diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index 988afc08..b337cd30 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -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 } } diff --git a/pkg/state/state.go b/pkg/state/state.go index cec6396d..27b48dd0 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -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 diff --git a/test/integration/run.sh b/test/integration/run.sh index 5f4dfdde..6826406c 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -107,6 +107,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes . ${dir}/test-cases/skip-diff-output.sh . ${dir}/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh . ${dir}/test-cases/kustomized-fetch.sh +. ${dir}/test-cases/issue-2503-kustomize-fetch.sh . ${dir}/test-cases/regression.sh . ${dir}/test-cases/secretssops.sh . ${dir}/test-cases/yaml-overwrite.sh diff --git a/test/integration/test-cases/issue-2503-kustomize-fetch.sh b/test/integration/test-cases/issue-2503-kustomize-fetch.sh new file mode 100644 index 00000000..110fc255 --- /dev/null +++ b/test/integration/test-cases/issue-2503-kustomize-fetch.sh @@ -0,0 +1,14 @@ +issue_2503_input_dir="${cases_dir}/issue-2503-kustomize-fetch/input" + +test_start "issue-2503 helmfile fetch with kustomization directory" + +info "Testing helmfile fetch with local kustomization directory (issue #2503)" + +for i in $(seq 3); do + info "Testing helmfile fetch with kustomization #$i" + issue_2503_tmp=$(mktemp -d) + ${helmfile} -f ${issue_2503_input_dir}/helmfile.yaml fetch --output-dir ${issue_2503_tmp} || fail "\"helmfile fetch\" shouldn't fail with kustomization directory" + rm -fr ${issue_2503_tmp} +done + +test_pass "issue-2503 helmfile fetch with kustomization directory" diff --git a/test/integration/test-cases/issue-2503-kustomize-fetch/input/helmfile.yaml b/test/integration/test-cases/issue-2503-kustomize-fetch/input/helmfile.yaml new file mode 100644 index 00000000..2dfe0f91 --- /dev/null +++ b/test/integration/test-cases/issue-2503-kustomize-fetch/input/helmfile.yaml @@ -0,0 +1,3 @@ +releases: +- name: test-kustomize + chart: ./kustomize diff --git a/test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/configmap.yaml b/test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/configmap.yaml new file mode 100644 index 00000000..4d913f17 --- /dev/null +++ b/test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-configmap +data: + key: value diff --git a/test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/kustomization.yaml b/test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/kustomization.yaml new file mode 100644 index 00000000..4eb24440 --- /dev/null +++ b/test/integration/test-cases/issue-2503-kustomize-fetch/input/kustomize/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- configmap.yaml