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 <matt.fisher@microsoft.com>
pull/6845/head
Matthew Fisher 6 years ago
parent 42dea4427b
commit 4ee00e41d5
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -15,7 +15,9 @@ limitations under the License.
package chart package chart
import "strings" import (
"strings"
)
// APIVersionV1 is the API version number for version 1. // APIVersionV1 is the API version number for version 1.
const APIVersionV1 = "v1" const APIVersionV1 = "v1"

@ -101,14 +101,14 @@ func ensureArchive(name string, raw *os.File) error {
// LoadArchiveFiles reads in files out of an archive into memory. This function // LoadArchiveFiles reads in files out of an archive into memory. This function
// performs important path security checks and should always be used before // performs important path security checks and should always be used before
// expanding a tarball // expanding a tarball
func LoadArchiveFiles(in io.Reader) ([]*BufferedFile, error) { func LoadArchiveFiles(in io.Reader) ([]*chart.File, error) {
unzipped, err := gzip.NewReader(in) unzipped, err := gzip.NewReader(in)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer unzipped.Close() defer unzipped.Close()
files := []*BufferedFile{} files := []*chart.File{}
tr := tar.NewReader(unzipped) tr := tar.NewReader(unzipped)
for { for {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
@ -167,7 +167,7 @@ func LoadArchiveFiles(in io.Reader) ([]*BufferedFile, error) {
return nil, err return nil, err
} }
files = append(files, &BufferedFile{Name: n, Data: b.Bytes()}) files = append(files, &chart.File{Name: n, Data: b.Bytes()})
b.Reset() b.Reset()
} }

@ -61,7 +61,7 @@ func LoadDir(dir string) (*chart.Chart, error) {
} }
rules.AddDefaults() rules.AddDefaults()
files := []*BufferedFile{} files := []*chart.File{}
topdir += string(filepath.Separator) topdir += string(filepath.Separator)
walk := func(name string, fi os.FileInfo, err error) error { 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) 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 return nil
} }
if err = sympath.Walk(topdir, walk); err != nil { if err = sympath.Walk(topdir, walk); err != nil {

@ -29,6 +29,12 @@ import (
"helm.sh/helm/v3/pkg/chart" "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. // ChartLoader loads a chart.
type ChartLoader interface { type ChartLoader interface {
Load() (*chart.Chart, error) Load() (*chart.Chart, error)
@ -62,16 +68,10 @@ func Load(name string) (*chart.Chart, error) {
return l.Load() 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. // 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) c := new(chart.Chart)
subcharts := make(map[string][]*BufferedFile) subcharts := make(map[string][]*chart.File)
for _, f := range files { for _, f := range files {
switch { switch {
@ -130,7 +130,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
fname := strings.TrimPrefix(f.Name, "charts/") fname := strings.TrimPrefix(f.Name, "charts/")
cname := strings.SplitN(fname, "/", 2)[0] 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: default:
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) 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: default:
// We have to trim the prefix off of every file, and ignore any file // We have to trim the prefix off of every file, and ignore any file
// that is in charts/, but isn't actually a chart. // 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 { for _, f := range files {
parts := strings.SplitN(f.Name, "/", 2) parts := strings.SplitN(f.Name, "/", 2)
if len(parts) < 2 { if len(parts) < 2 {

Loading…
Cancel
Save