diff --git a/.golangci.yaml b/.golangci.yaml index 99add513..dc6d3add 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -45,7 +45,7 @@ linters: lines: 280 statements: 140 gocognit: - min-complexity: 100 + min-complexity: 110 goconst: min-len: 3 min-occurrences: 8 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/app/app.go b/pkg/app/app.go index 16a9c720..19024459 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -345,8 +345,7 @@ func (a *App) Fetch(c FetchConfigProvider) error { OutputDir: c.OutputDir(), OutputDirTemplate: c.OutputDirTemplate(), Concurrency: c.Concurrency(), - }, func() { - }) + }, func() {}) if prepErr != nil { errs = append(errs, prepErr) diff --git a/pkg/filesystem/fs.go b/pkg/filesystem/fs.go index a79fe1e9..89bd55ce 100644 --- a/pkg/filesystem/fs.go +++ b/pkg/filesystem/fs.go @@ -6,6 +6,8 @@ import ( "os" "path/filepath" "time" + + copyDir "github.com/otiai10/copy" ) type fileStat struct { @@ -36,6 +38,7 @@ type FileSystem struct { Chdir func(string) error Abs func(string) (string, error) EvalSymlinks func(string) (string, error) + CopyDir func(src, dst string) error } func DefaultFileSystem() *FileSystem { @@ -55,6 +58,7 @@ func DefaultFileSystem() *FileSystem { dfs.DirectoryExistsAt = dfs.directoryExistsDefault dfs.FileExists = dfs.fileExistsDefault dfs.Abs = dfs.absDefault + dfs.CopyDir = dfs.copyDirDefault return &dfs } @@ -100,6 +104,9 @@ func FromFileSystem(params FileSystem) *FileSystem { if params.Dir != nil { dfs.Dir = params.Dir } + if params.CopyDir != nil { + dfs.CopyDir = params.CopyDir + } return dfs } @@ -180,3 +187,8 @@ func (filesystem *FileSystem) absDefault(path string) (string, error) { } 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}) +} diff --git a/pkg/state/state.go b/pkg/state/state.go index 428cf414..0e2659d9 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -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 // a broken remote chart won't completely block their job. 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 } else if !opts.ForceDownload { 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..da439450 --- /dev/null +++ b/test/integration/test-cases/fetch-forl-local-chart.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" \ 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