refactor(filesystem): add CopyDir method and optimize Fetch function (#2111)
* refactor(filesystem): add CopyDir method and optimize Fetch function Signed-off-by: yxxhero <aiopsclub@163.com> * fix(state): conditionally prepare charts for local helmfile command Signed-off-by: yxxhero <aiopsclub@163.com> * fix(state): conditionally prepare charts for local helmfile command Signed-off-by: yxxhero <aiopsclub@163.com> * refactor(state): optimize chart path generation and update dependencies Signed-off-by: yxxhero <aiopsclub@163.com> * fix(test): update path in fetch-forl-local-chart test Signed-off-by: yxxhero <aiopsclub@163.com> * add more test cases Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
b0911ab1a2
commit
a76bec234c
|
|
@ -45,7 +45,7 @@ linters:
|
||||||
lines: 280
|
lines: 280
|
||||||
statements: 140
|
statements: 140
|
||||||
gocognit:
|
gocognit:
|
||||||
min-complexity: 100
|
min-complexity: 110
|
||||||
goconst:
|
goconst:
|
||||||
min-len: 3
|
min-len: 3
|
||||||
min-occurrences: 8
|
min-occurrences: 8
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -84,7 +84,7 @@ require (
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 // 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/pkg/errors v0.9.1
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/ryanuber/go-glob v1.0.0 // indirect
|
github.com/ryanuber/go-glob v1.0.0 // indirect
|
||||||
|
|
|
||||||
|
|
@ -345,8 +345,7 @@ func (a *App) Fetch(c FetchConfigProvider) error {
|
||||||
OutputDir: c.OutputDir(),
|
OutputDir: c.OutputDir(),
|
||||||
OutputDirTemplate: c.OutputDirTemplate(),
|
OutputDirTemplate: c.OutputDirTemplate(),
|
||||||
Concurrency: c.Concurrency(),
|
Concurrency: c.Concurrency(),
|
||||||
}, func() {
|
}, func() {})
|
||||||
})
|
|
||||||
|
|
||||||
if prepErr != nil {
|
if prepErr != nil {
|
||||||
errs = append(errs, prepErr)
|
errs = append(errs, prepErr)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
copyDir "github.com/otiai10/copy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fileStat struct {
|
type fileStat struct {
|
||||||
|
|
@ -36,6 +38,7 @@ type FileSystem struct {
|
||||||
Chdir func(string) error
|
Chdir func(string) error
|
||||||
Abs func(string) (string, error)
|
Abs func(string) (string, error)
|
||||||
EvalSymlinks func(string) (string, error)
|
EvalSymlinks func(string) (string, error)
|
||||||
|
CopyDir func(src, dst string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultFileSystem() *FileSystem {
|
func DefaultFileSystem() *FileSystem {
|
||||||
|
|
@ -55,6 +58,7 @@ func DefaultFileSystem() *FileSystem {
|
||||||
dfs.DirectoryExistsAt = dfs.directoryExistsDefault
|
dfs.DirectoryExistsAt = dfs.directoryExistsDefault
|
||||||
dfs.FileExists = dfs.fileExistsDefault
|
dfs.FileExists = dfs.fileExistsDefault
|
||||||
dfs.Abs = dfs.absDefault
|
dfs.Abs = dfs.absDefault
|
||||||
|
dfs.CopyDir = dfs.copyDirDefault
|
||||||
return &dfs
|
return &dfs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,6 +104,9 @@ func FromFileSystem(params FileSystem) *FileSystem {
|
||||||
if params.Dir != nil {
|
if params.Dir != nil {
|
||||||
dfs.Dir = params.Dir
|
dfs.Dir = params.Dir
|
||||||
}
|
}
|
||||||
|
if params.CopyDir != nil {
|
||||||
|
dfs.CopyDir = params.CopyDir
|
||||||
|
}
|
||||||
return dfs
|
return dfs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,3 +187,8 @@ func (filesystem *FileSystem) absDefault(path string) (string, error) {
|
||||||
}
|
}
|
||||||
return filepath.Abs(path)
|
return filepath.Abs(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copyDirDefault recursively copies a directory tree, preserving permissions.
|
||||||
|
func (filesystem *FileSystem) copyDirDefault(src string, dst string) error {
|
||||||
|
return copyDir.Copy(src, dst, copyDir.Options{Sync: true})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1372,6 +1372,18 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
|
||||||
// for a remote chart, so that the user can notice/fix the issue in a local chart while
|
// for a remote chart, so that the user can notice/fix the issue in a local chart while
|
||||||
// a broken remote chart won't completely block their job.
|
// a broken remote chart won't completely block their job.
|
||||||
chartPath = normalizedChart
|
chartPath = normalizedChart
|
||||||
|
if helmfileCommand == "pull" && isLocal {
|
||||||
|
chartAbsPath := strings.TrimSuffix(filepath.Clean(normalizedChart), "/")
|
||||||
|
chartPath, err = generateChartPath(filepath.Base(chartAbsPath), dir, release, opts.OutputDirTemplate)
|
||||||
|
if err != nil {
|
||||||
|
results <- &chartPrepareResult{err: err}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := st.fs.CopyDir(normalizedChart, filepath.Clean(chartPath)); err != nil {
|
||||||
|
results <- &chartPrepareResult{err: err}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildDeps = !skipDeps
|
buildDeps = !skipDeps
|
||||||
} else if !opts.ForceDownload {
|
} else if !opts.ForceDownload {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
|
||||||
|
|
||||||
# TEST CASES----------------------------------------------------------------------------------------------------------
|
# TEST CASES----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
. ${dir}/test-cases/fetch-forl-local-chart.sh
|
||||||
. ${dir}/test-cases/suppress-output-line-regex.sh
|
. ${dir}/test-cases/suppress-output-line-regex.sh
|
||||||
. ${dir}/test-cases/chartify-jsonPatches-and-strategicMergePatches.sh
|
. ${dir}/test-cases/chartify-jsonPatches-and-strategicMergePatches.sh
|
||||||
. ${dir}/test-cases/include-template-func.sh
|
. ${dir}/test-cases/include-template-func.sh
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
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}/helmfile-tests/local-chart/raw/latest/Chart.yaml || fail "Chart.yaml should exist in the fetched local chart directory"
|
||||||
|
cat ${fetch_forl_local_chart_tmp}/helmfile-tests/local-chart/raw/latest/templates/resources.yaml || fail "templates/resources.yaml should exist in the fetched local chart directory"
|
||||||
|
echo code=$?
|
||||||
|
|
||||||
|
test_pass "$case_title"
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
releases:
|
||||||
|
- name: local-chart
|
||||||
|
chart: ../../../charts/raw
|
||||||
|
namespace: local-chart
|
||||||
Loading…
Reference in New Issue