mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-19 00:13:37 +02:00
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:
+1
-2
@@ -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)
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user