fix: oci pull directory conflict when download twice (#914)
* fix: oci pull directory conflict when download twice Signed-off-by: yxxhero <aiopsclub@163.com> * add test cases
This commit is contained in:
parent
d44b94cd68
commit
67ab08ab5e
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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"
|
||||
Loading…
Reference in New Issue