From 72be00c6fc2cdcd8e095cd39f47cba72aa08ca4e Mon Sep 17 00:00:00 2001 From: Matt Butcher <mbutcher@engineyard.com> Date: Mon, 6 Jun 2016 21:04:38 -0600 Subject: [PATCH] fix(chartutil): update 'fetch' and 'package' to use chartutil. --- cmd/helm/fetch.go | 5 ++--- cmd/helm/package.go | 7 +++--- pkg/chartutil/expand.go | 47 +++++++++++++++++++++++++++++++++++++++++ pkg/repo/local.go | 7 +++--- 4 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 pkg/chartutil/expand.go diff --git a/cmd/helm/fetch.go b/cmd/helm/fetch.go index 4505975d4..fbdc1aa76 100644 --- a/cmd/helm/fetch.go +++ b/cmd/helm/fetch.go @@ -9,8 +9,7 @@ import ( "strings" "github.com/spf13/cobra" - - "k8s.io/helm/pkg/chart" + "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/repo" ) @@ -56,7 +55,7 @@ func fetch(cmd *cobra.Command, args []string) error { defer resp.Body.Close() if untarFile { - return chart.Expand(untarDir, resp.Body) + return chartutil.Expand(untarDir, resp.Body) } p := strings.Split(u.String(), "/") return saveChartFile(p[len(p)-1], resp.Body) diff --git a/cmd/helm/package.go b/cmd/helm/package.go index f6277924f..acf0c5e55 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -6,8 +6,7 @@ import ( "path/filepath" "github.com/spf13/cobra" - - "k8s.io/helm/pkg/chart" + "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/repo" ) @@ -50,7 +49,7 @@ func runPackage(cmd *cobra.Command, args []string) error { return err } - ch, err := chart.LoadDir(path) + ch, err := chartutil.LoadDir(path) if err != nil { return err } @@ -60,7 +59,7 @@ func runPackage(cmd *cobra.Command, args []string) error { if err != nil { return err } - name, err := chart.Save(ch, cwd) + name, err := chartutil.Save(ch, cwd) if err == nil && flagDebug { cmd.Printf("Saved %s to current directory\n", name) } diff --git a/pkg/chartutil/expand.go b/pkg/chartutil/expand.go new file mode 100644 index 000000000..6900e7dee --- /dev/null +++ b/pkg/chartutil/expand.go @@ -0,0 +1,47 @@ +package chartutil + +import ( + "archive/tar" + "compress/gzip" + "io" + "os" + "path/filepath" +) + +// Expand uncompresses and extracts a chart into the specified directory. +func Expand(dir string, r io.Reader) error { + gr, err := gzip.NewReader(r) + if err != nil { + return err + } + defer gr.Close() + tr := tar.NewReader(gr) + for { + header, err := tr.Next() + if err == io.EOF { + break + } else if err != nil { + return err + } + + path := filepath.Clean(filepath.Join(dir, header.Name)) + info := header.FileInfo() + if info.IsDir() { + if err = os.MkdirAll(path, info.Mode()); err != nil { + return err + } + continue + } + + file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode()) + if err != nil { + return err + } + defer file.Close() + _, err = io.Copy(file, tr) + if err != nil { + return err + } + } + return nil +} diff --git a/pkg/repo/local.go b/pkg/repo/local.go index 72282e5ea..90d05363b 100644 --- a/pkg/repo/local.go +++ b/pkg/repo/local.go @@ -7,7 +7,8 @@ import ( "path/filepath" "strings" - "k8s.io/helm/pkg/chart" + "k8s.io/helm/pkg/chartutil" + "k8s.io/helm/pkg/proto/hapi/chart" ) var localRepoPath string @@ -42,7 +43,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, file string) { // AddChartToLocalRepo saves a chart in the given path and then reindexes the index file func AddChartToLocalRepo(ch *chart.Chart, path string) error { - _, err := chart.Save(ch, path) + _, err := chartutil.Save(ch, path) if err != nil { return err } @@ -51,7 +52,7 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error { // Reindex adds an entry to the index file at the given path func Reindex(ch *chart.Chart, path string) error { - name := ch.Chartfile().Name + "-" + ch.Chartfile().Version + name := ch.Metadata.Name + "-" + ch.Metadata.Version y, err := LoadIndexFile(path) if err != nil { return err -- GitLab