From 687944815c9ddc2a54ac2af27027cabab8c9e2af Mon Sep 17 00:00:00 2001 From: yxxhero Date: Mon, 28 Jul 2025 13:12:46 +0800 Subject: [PATCH] refactor(state): optimize chart path generation and update dependencies Signed-off-by: yxxhero --- Vagrantfile | 19 ------------------- go.mod | 2 +- pkg/state/state.go | 4 ++-- test/integration/run.sh | 1 + .../test-cases/fetch-forl-local-chart.sh | 14 ++++++++++++++ .../input/helmfile.yaml.gotmpl | 4 ++++ 6 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 Vagrantfile create mode 100755 test/integration/test-cases/fetch-forl-local-chart.sh create mode 100644 test/integration/test-cases/fetch-forl-local-chart/input/helmfile.yaml.gotmpl diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 97c18512..00000000 --- a/Vagrantfile +++ /dev/null @@ -1,19 +0,0 @@ -Vagrant.configure("2") do |config| - config.vm.box = "ubuntu/focal64" - config.vm.hostname = "minikube.box" - config.vm.provision :shell, privileged: false, - inline: <<-EOS - set -e - sudo apt-get update - sudo apt-get install -y make docker.io - sudo systemctl start docker - sudo usermod -G docker $USER - cd /vagrant/.circleci - make all - EOS - - config.vm.provider "virtualbox" do |v| - v.memory = 2048 - v.cpus = 2 - end -end diff --git a/go.mod b/go.mod index d7a54b64..635dd888 100644 --- a/go.mod +++ b/go.mod @@ -84,7 +84,7 @@ require ( github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect - github.com/otiai10/copy v1.14.1 // indirect + github.com/otiai10/copy v1.14.1 github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect diff --git a/pkg/state/state.go b/pkg/state/state.go index fa355b8f..0e2659d9 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1373,8 +1373,8 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre // a broken remote chart won't completely block their job. chartPath = normalizedChart if helmfileCommand == "pull" && isLocal { - // copy chart to a temporary directory - chartPath, err = generateChartPath(chartName, dir, release, opts.OutputDirTemplate) + chartAbsPath := strings.TrimSuffix(filepath.Clean(normalizedChart), "/") + chartPath, err = generateChartPath(filepath.Base(chartAbsPath), dir, release, opts.OutputDirTemplate) if err != nil { results <- &chartPrepareResult{err: err} return diff --git a/test/integration/run.sh b/test/integration/run.sh index ab3b8b8b..1e501553 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -80,6 +80,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes # TEST CASES---------------------------------------------------------------------------------------------------------- +. ${dir}/test-cases/fetch-forl-local-chart.sh . ${dir}/test-cases/suppress-output-line-regex.sh . ${dir}/test-cases/chartify-jsonPatches-and-strategicMergePatches.sh . ${dir}/test-cases/include-template-func.sh diff --git a/test/integration/test-cases/fetch-forl-local-chart.sh b/test/integration/test-cases/fetch-forl-local-chart.sh new file mode 100755 index 00000000..fa779a2f --- /dev/null +++ b/test/integration/test-cases/fetch-forl-local-chart.sh @@ -0,0 +1,14 @@ +fetch_forl_local_chart_input_dir="${cases_dir}/fetch-forl-local-chart/input" + +fetch_forl_local_chart_tmp=$(mktemp -d) + +case_title="fetch for local chart" + +test_start "$case_title" + +info "Comparing fetch-forl-local-chart diff log #$i" +${helmfile} -f ${fetch_forl_local_chart_input_dir}/helmfile.yaml.gotmpl fetch --output-dir ${fetch_forl_local_chart_tmp} || fail "\"helmfile fetch\" shouldn't fail" +cat ${fetch_forl_local_chart_tmp}/local-chart/local-chart/raw/latest/Chart.yaml || fail "Chart.yaml should exist in the fetched local chart directory" +echo code=$? + +test_pass "$case_title" \ No newline at end of file diff --git a/test/integration/test-cases/fetch-forl-local-chart/input/helmfile.yaml.gotmpl b/test/integration/test-cases/fetch-forl-local-chart/input/helmfile.yaml.gotmpl new file mode 100644 index 00000000..1ccbdfb9 --- /dev/null +++ b/test/integration/test-cases/fetch-forl-local-chart/input/helmfile.yaml.gotmpl @@ -0,0 +1,4 @@ +releases: +- name: local-chart + chart: ../../../charts/raw + namespace: local-chart \ No newline at end of file