fix(chartutil): update 'fetch' and 'package' to use chartutil.

pull/793/head
Matt Butcher 8 years ago
parent cded50e34f
commit 72be00c6fc

@ -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)

@ -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)
}

@ -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
}

@ -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

Loading…
Cancel
Save