From 4ee00e41d502465136402a4dd167e5914badea00 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Wed, 30 Oct 2019 14:16:14 -0700 Subject: [PATCH] ref(chart): replace loader.BufferedFile with chart.File Using Go's gradual code migration feature to deprecate BufferedFile. load_test.go continues to work even with this refactor. Signed-off-by: Matthew Fisher --- pkg/chart/chart.go | 4 +++- pkg/chart/loader/archive.go | 6 +++--- pkg/chart/loader/directory.go | 4 ++-- pkg/chart/loader/load.go | 20 ++++++++++---------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index f36cf8236..079c5b10a 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -15,7 +15,9 @@ limitations under the License. package chart -import "strings" +import ( + "strings" +) // APIVersionV1 is the API version number for version 1. const APIVersionV1 = "v1" diff --git a/pkg/chart/loader/archive.go b/pkg/chart/loader/archive.go index 3c50fe379..49ae2db18 100644 --- a/pkg/chart/loader/archive.go +++ b/pkg/chart/loader/archive.go @@ -101,14 +101,14 @@ func ensureArchive(name string, raw *os.File) error { // LoadArchiveFiles reads in files out of an archive into memory. This function // performs important path security checks and should always be used before // expanding a tarball -func LoadArchiveFiles(in io.Reader) ([]*BufferedFile, error) { +func LoadArchiveFiles(in io.Reader) ([]*chart.File, error) { unzipped, err := gzip.NewReader(in) if err != nil { return nil, err } defer unzipped.Close() - files := []*BufferedFile{} + files := []*chart.File{} tr := tar.NewReader(unzipped) for { b := bytes.NewBuffer(nil) @@ -167,7 +167,7 @@ func LoadArchiveFiles(in io.Reader) ([]*BufferedFile, error) { return nil, err } - files = append(files, &BufferedFile{Name: n, Data: b.Bytes()}) + files = append(files, &chart.File{Name: n, Data: b.Bytes()}) b.Reset() } diff --git a/pkg/chart/loader/directory.go b/pkg/chart/loader/directory.go index a12c5158e..99be6784c 100644 --- a/pkg/chart/loader/directory.go +++ b/pkg/chart/loader/directory.go @@ -61,7 +61,7 @@ func LoadDir(dir string) (*chart.Chart, error) { } rules.AddDefaults() - files := []*BufferedFile{} + files := []*chart.File{} topdir += string(filepath.Separator) walk := func(name string, fi os.FileInfo, err error) error { @@ -104,7 +104,7 @@ func LoadDir(dir string) (*chart.Chart, error) { return errors.Wrapf(err, "error reading %s", n) } - files = append(files, &BufferedFile{Name: n, Data: data}) + files = append(files, &chart.File{Name: n, Data: data}) return nil } if err = sympath.Walk(topdir, walk); err != nil { diff --git a/pkg/chart/loader/load.go b/pkg/chart/loader/load.go index f04c0e9b3..3ceece1f7 100644 --- a/pkg/chart/loader/load.go +++ b/pkg/chart/loader/load.go @@ -29,6 +29,12 @@ import ( "helm.sh/helm/v3/pkg/chart" ) +// BufferedFile represents a file as a name/value pair. +// +// By convention, name is a relative path within the scope of the chart's +// base directory. +type BufferedFile = chart.File + // ChartLoader loads a chart. type ChartLoader interface { Load() (*chart.Chart, error) @@ -62,16 +68,10 @@ func Load(name string) (*chart.Chart, error) { return l.Load() } -// BufferedFile represents an archive file buffered for later processing. -type BufferedFile struct { - Name string - Data []byte -} - // LoadFiles loads from in-memory files. -func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { +func LoadFiles(files []*chart.File) (*chart.Chart, error) { c := new(chart.Chart) - subcharts := make(map[string][]*BufferedFile) + subcharts := make(map[string][]*chart.File) for _, f := range files { switch { @@ -130,7 +130,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { fname := strings.TrimPrefix(f.Name, "charts/") cname := strings.SplitN(fname, "/", 2)[0] - subcharts[cname] = append(subcharts[cname], &BufferedFile{Name: fname, Data: f.Data}) + subcharts[cname] = append(subcharts[cname], &chart.File{Name: fname, Data: f.Data}) default: c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) } @@ -156,7 +156,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { default: // We have to trim the prefix off of every file, and ignore any file // that is in charts/, but isn't actually a chart. - buff := make([]*BufferedFile, 0, len(files)) + buff := make([]*chart.File, 0, len(files)) for _, f := range files { parts := strings.SplitN(f.Name, "/", 2) if len(parts) < 2 {