From bb4445f4c68409ad22a8d953852f207b0cc4e09d Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 29 Aug 2018 11:18:54 +0200 Subject: [PATCH] Unpack also the charts downloaded from a local repository Signed-off-by: Cosmin Cojocar --- pkg/downloader/manager.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 0f4e7b9c0..6c4e3e4be 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -294,12 +294,19 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error { if m.Debug { fmt.Fprintf(m.Out, "Archiving %s from repo %s\n", dep.Name, dep.Repository) } - ver, err := tarFromLocalDir(m.ChartPath, dep.Name, dep.Repository, dep.Version) + ver, archiveFile, err := tarFromLocalDir(m.ChartPath, dep.Name, dep.Repository, dep.Version) if err != nil { saveError = err break } dep.Version = ver + if m.Recursive { + fmt.Fprintln(m.Out, "Unpacking:", archiveFile) + err := chartutil.ExpandFile(destPath, archiveFile) + if err != nil { + return fmt.Errorf("could not unpack %s: %s", archiveFile, err) + } + } continue } @@ -687,40 +694,40 @@ func writeLock(chartpath string, lock *chartutil.RequirementsLock) error { return ioutil.WriteFile(dest, data, 0644) } -// tarFromLocalDir archive a dep chart from local directory and save it into charts/ -func tarFromLocalDir(chartpath string, name string, repo string, version string) (string, error) { +// archive a dep chart from local directory and save it into charts/ +func tarFromLocalDir(chartpath string, name string, repo string, version string) (string, string, error) { destPath := filepath.Join(chartpath, "charts") if !strings.HasPrefix(repo, "file://") { - return "", fmt.Errorf("wrong format: chart %s repository %s", name, repo) + return "", "", fmt.Errorf("wrong format: chart %s repository %s", name, repo) } origPath, err := resolver.GetLocalPath(repo, chartpath) if err != nil { - return "", err + return "", "", err } ch, err := chartutil.LoadDir(origPath) if err != nil { - return "", err + return "", "", err } constraint, err := semver.NewConstraint(version) if err != nil { - return "", fmt.Errorf("dependency %s has an invalid version/constraint format: %s", name, err) + return "", "", fmt.Errorf("dependency %s has an invalid version/constraint format: %s", name, err) } v, err := semver.NewVersion(ch.Metadata.Version) if err != nil { - return "", err + return "", "", err } if constraint.Check(v) { - _, err = chartutil.Save(ch, destPath) - return ch.Metadata.Version, err + archiveFile, err := chartutil.Save(ch, destPath) + return ch.Metadata.Version, archiveFile, err } - return "", fmt.Errorf("can't get a valid version for dependency %s", name) + return "", "", fmt.Errorf("can't get a valid version for dependency %s", name) } // move files from tmppath to destpath