diff --git a/pkg/app/init_test.go b/pkg/app/init_test.go index 34e9420c..f9f40b3e 100644 --- a/pkg/app/init_test.go +++ b/pkg/app/init_test.go @@ -5,7 +5,7 @@ import ( "net/http" "net/http/httptest" "os" - "path" + "path/filepath" "regexp" "testing" ) @@ -55,9 +55,9 @@ func TestDownloadfile(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { dir := t.TempDir() - downfile := path.Join(dir, "down.txt") + downfile := filepath.Join(dir, "down.txt") if c.filepath != "" { - downfile = path.Join(dir, c.filepath) + downfile = filepath.Join(dir, c.filepath) } ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/filesystem/fs_test.go b/pkg/filesystem/fs_test.go index 2431df90..5f1e01f3 100644 --- a/pkg/filesystem/fs_test.go +++ b/pkg/filesystem/fs_test.go @@ -4,7 +4,7 @@ import ( "errors" "io/fs" "os" - "path" + "path/filepath" "strings" "testing" ) @@ -102,7 +102,7 @@ func TestFsTeadFile(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { dir := t.TempDir() - yamlPath := path.Join(dir, c.path) + yamlPath := filepath.Join(dir, c.path) dfs := DefaultFileSystem() tmpfile, err := os.Create(yamlPath) diff --git a/pkg/state/state.go b/pkg/state/state.go index 24c6b5dd..67fd3a4b 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "os" - "path" "path/filepath" "regexp" "sort" @@ -431,7 +430,7 @@ const MissingFileHandlerWarn = "Warn" // MissingFileHandlerDebug is the debug returned when a file is missing const MissingFileHandlerDebug = "Debug" -var DefaultFetchOutputDirTemplate = path.Join( +var DefaultFetchOutputDirTemplate = filepath.Join( "{{ .OutputDir }}{{ if .Release.Namespace }}", "{{ .Release.Namespace }}{{ end }}{{ if .Release.KubeContext }}", "{{ .Release.KubeContext }}{{ end }}", @@ -3477,15 +3476,19 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm pathElems = append(pathElems, release.Name, chartName, chartVersion) - chartPath := path.Join(pathElems...) + chartPath := filepath.Join(pathElems...) - err := helm.ChartPull(qualifiedChartName, chartPath) - if err != nil { - return nil, err - } - err = helm.ChartExport(qualifiedChartName, chartPath) - if err != nil { - return nil, err + if st.fs.DirectoryExistsAt(chartPath) { + st.logger.Debugf("chart already exists at %s", chartPath) + } else { + err := helm.ChartPull(qualifiedChartName, chartPath) + if err != nil { + return nil, err + } + err = helm.ChartExport(qualifiedChartName, chartPath) + if err != nil { + return nil, err + } } fullChartPath, err := findChartDirectory(chartPath) diff --git a/test/integration/run.sh b/test/integration/run.sh index 1000906f..31407cc3 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -76,6 +76,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes # TEST CASES---------------------------------------------------------------------------------------------------------- +. ${dir}/test-cases/helmfile-double-fetch.sh . ${dir}/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh . ${dir}/test-cases/kustomized-fetch.sh . ${dir}/test-cases/happypath.sh diff --git a/test/integration/test-cases/helmfile-double-fetch.sh b/test/integration/test-cases/helmfile-double-fetch.sh new file mode 100644 index 00000000..4de01f9f --- /dev/null +++ b/test/integration/test-cases/helmfile-double-fetch.sh @@ -0,0 +1,13 @@ +helmfile_double_fetch_case_input_dir="${cases_dir}/helmfile-double-fetch/input" + +config_file="helmfile.yaml" + +test_start "helmfile fetch with helmfile_double_fetch" + +info "Comparing fetch/helmfile_double_fetch_first" +${helmfile} -f ${helmfile_double_fetch_case_input_dir}/${config_file} fetch --output-dir /tmp/chartdir || fail "\"helmfile fetch\" shouldn't fail" + +info "Comparing template/helmfile_double_fetch_second" +${helmfile} -f ${helmfile_double_fetch_case_input_dir}/${config_file} fetch --output-dir /tmp/chartdir || fail "\"helmfile fetch\" shouldn't fail" + +test_pass "helmfile fetch with helmfile_double_fetch" \ No newline at end of file diff --git a/test/integration/test-cases/helmfile-double-fetch/input/helmfile.yaml b/test/integration/test-cases/helmfile-double-fetch/input/helmfile.yaml new file mode 100644 index 00000000..4aaa271f --- /dev/null +++ b/test/integration/test-cases/helmfile-double-fetch/input/helmfile.yaml @@ -0,0 +1,8 @@ +repositories: + - name: docker + url: registry-1.docker.io + oci: true +releases: + - name: docker/bitnamicharts/matomo + chart: docker/bitnamicharts/matomo + version: "1.1.2" \ No newline at end of file