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"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -55,9 +55,9 @@ func TestDownloadfile(t *testing.T) {
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
downfile := path.Join(dir, "down.txt")
|
downfile := filepath.Join(dir, "down.txt")
|
||||||
if c.filepath != "" {
|
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) {
|
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -102,7 +102,7 @@ func TestFsTeadFile(t *testing.T) {
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
yamlPath := path.Join(dir, c.path)
|
yamlPath := filepath.Join(dir, c.path)
|
||||||
|
|
||||||
dfs := DefaultFileSystem()
|
dfs := DefaultFileSystem()
|
||||||
tmpfile, err := os.Create(yamlPath)
|
tmpfile, err := os.Create(yamlPath)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -431,7 +430,7 @@ const MissingFileHandlerWarn = "Warn"
|
||||||
// MissingFileHandlerDebug is the debug returned when a file is missing
|
// MissingFileHandlerDebug is the debug returned when a file is missing
|
||||||
const MissingFileHandlerDebug = "Debug"
|
const MissingFileHandlerDebug = "Debug"
|
||||||
|
|
||||||
var DefaultFetchOutputDirTemplate = path.Join(
|
var DefaultFetchOutputDirTemplate = filepath.Join(
|
||||||
"{{ .OutputDir }}{{ if .Release.Namespace }}",
|
"{{ .OutputDir }}{{ if .Release.Namespace }}",
|
||||||
"{{ .Release.Namespace }}{{ end }}{{ if .Release.KubeContext }}",
|
"{{ .Release.Namespace }}{{ end }}{{ if .Release.KubeContext }}",
|
||||||
"{{ .Release.KubeContext }}{{ end }}",
|
"{{ .Release.KubeContext }}{{ end }}",
|
||||||
|
|
@ -3477,8 +3476,11 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm
|
||||||
|
|
||||||
pathElems = append(pathElems, release.Name, chartName, chartVersion)
|
pathElems = append(pathElems, release.Name, chartName, chartVersion)
|
||||||
|
|
||||||
chartPath := path.Join(pathElems...)
|
chartPath := filepath.Join(pathElems...)
|
||||||
|
|
||||||
|
if st.fs.DirectoryExistsAt(chartPath) {
|
||||||
|
st.logger.Debugf("chart already exists at %s", chartPath)
|
||||||
|
} else {
|
||||||
err := helm.ChartPull(qualifiedChartName, chartPath)
|
err := helm.ChartPull(qualifiedChartName, chartPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -3487,6 +3489,7 @@ func (st *HelmState) getOCIChart(release *ReleaseSpec, tempDir string, helm helm
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fullChartPath, err := findChartDirectory(chartPath)
|
fullChartPath, err := findChartDirectory(chartPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
|
||||||
|
|
||||||
# TEST CASES----------------------------------------------------------------------------------------------------------
|
# TEST CASES----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
. ${dir}/test-cases/helmfile-double-fetch.sh
|
||||||
. ${dir}/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh
|
. ${dir}/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh
|
||||||
. ${dir}/test-cases/kustomized-fetch.sh
|
. ${dir}/test-cases/kustomized-fetch.sh
|
||||||
. ${dir}/test-cases/happypath.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