-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Franck Kambiwa
committed
Sep 25, 2020
1 parent
b159ca8
commit 31c75e8
Showing
95 changed files
with
726 additions
and
10,450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package manager | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"k8s.io/helm/pkg/ignore" | ||
"k8s.io/helm/pkg/sympath" | ||
|
||
"helm.sh/helm/v3/pkg/chart" | ||
"helm.sh/helm/v3/pkg/chart/loader" | ||
) | ||
|
||
var utf8bom = []byte{0xEF, 0xBB, 0xBF} | ||
|
||
// LoadDir loads from a directory. | ||
// | ||
// This loads charts only from directories. | ||
func LoadDir(dir string, p *Package) (*chart.Chart, error) { | ||
topdir, err := filepath.Abs(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Just used for errors. | ||
c := &chart.Chart{} | ||
|
||
rules := ignore.Empty() | ||
ifile := filepath.Join(topdir, ignore.HelmIgnore) | ||
if _, err := os.Stat(ifile); err == nil { | ||
r, err := ignore.ParseFile(ifile) | ||
if err != nil { | ||
return c, err | ||
} | ||
rules = r | ||
} | ||
rules.AddDefaults() | ||
|
||
files := []*loader.BufferedFile{} | ||
topdir += string(filepath.Separator) | ||
|
||
walk := func(name string, fi os.FileInfo, err error) error { | ||
n := strings.TrimPrefix(name, topdir) | ||
if n == "" { | ||
// No need to process top level. Avoid bug with helmignore .* matching | ||
// empty names. See issue 1779. | ||
return nil | ||
} | ||
|
||
// Normalize to / since it will also work on Windows | ||
n = filepath.ToSlash(n) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
if fi.IsDir() { | ||
// Directory-based ignore rules should involve skipping the entire | ||
// contents of that directory. | ||
if rules.Ignore(n, fi) { | ||
return filepath.SkipDir | ||
} | ||
return nil | ||
} | ||
|
||
// If a .helmignore file matches, skip this file. | ||
if rules.Ignore(n, fi) { | ||
return nil | ||
} | ||
|
||
// Irregular files include devices, sockets, and other uses of files that | ||
// are not regular files. In Go they have a file mode type bit set. | ||
// See https://golang.org/pkg/os/#FileMode for examples. | ||
if !fi.Mode().IsRegular() { | ||
return fmt.Errorf("cannot load irregular file %s as it has file mode type bits set", name) | ||
} | ||
|
||
data, err := ioutil.ReadFile(name) | ||
if err != nil { | ||
return errors.Wrapf(err, "error reading %s", n) | ||
} | ||
|
||
data = bytes.TrimPrefix(data, utf8bom) | ||
|
||
files = append(files, &loader.BufferedFile{Name: n, Data: data}) | ||
return nil | ||
} | ||
if err = sympath.Walk(topdir, walk); err != nil { | ||
return c, err | ||
} | ||
|
||
return LoadFiles(files, p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package manager | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"helm.sh/helm/v3/pkg/chart" | ||
"helm.sh/helm/v3/pkg/chart/loader" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
// LoadFiles loads from in-memory files. | ||
func LoadFiles(files []*loader.BufferedFile, p *Package) (*chart.Chart, error) { | ||
c := new(chart.Chart) | ||
subcharts := make(map[string][]*loader.BufferedFile) | ||
|
||
for _, f := range files { | ||
c.Raw = append(c.Raw, &chart.File{Name: f.Name, Data: f.Data}) | ||
switch { | ||
case f.Name == "Chart.yaml": | ||
if c.Metadata == nil { | ||
c.Metadata = new(chart.Metadata) | ||
} | ||
if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil { | ||
return c, errors.Wrap(err, "cannot load Chart.yaml") | ||
} | ||
// NOTE(bacongobbler): while the chart specification says that APIVersion must be set, | ||
// Helm 2 accepted charts that did not provide an APIVersion in their chart metadata. | ||
// Because of that, if APIVersion is unset, we should assume we're loading a v1 chart. | ||
if c.Metadata.APIVersion == "" { | ||
c.Metadata.APIVersion = chart.APIVersionV1 | ||
} | ||
case f.Name == "Chart.lock": | ||
c.Lock = new(chart.Lock) | ||
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil { | ||
return c, errors.Wrap(err, "cannot load Chart.lock") | ||
} | ||
case f.Name == "values.yaml": | ||
c.Values = make(map[string]interface{}) | ||
if err := yaml.Unmarshal(f.Data, &c.Values); err != nil { | ||
return c, errors.Wrap(err, "cannot load values.yaml") | ||
} | ||
case f.Name == "values.schema.json": | ||
c.Schema = f.Data | ||
|
||
// Deprecated: requirements.yaml is deprecated use Chart.yaml. | ||
// We will handle it for you because we are nice people | ||
case f.Name == "requirements.yaml": | ||
if c.Metadata == nil { | ||
c.Metadata = new(chart.Metadata) | ||
} | ||
if c.Metadata.APIVersion != chart.APIVersionV1 { | ||
log.Printf("Warning: Dependencies are handled in Chart.yaml since apiVersion \"v2\". We recommend migrating dependencies to Chart.yaml.") | ||
} | ||
if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil { | ||
return c, errors.Wrap(err, "cannot load requirements.yaml") | ||
} | ||
if c.Metadata.APIVersion == chart.APIVersionV1 { | ||
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) | ||
} | ||
// Deprecated: requirements.lock is deprecated use Chart.lock. | ||
case f.Name == "requirements.lock": | ||
c.Lock = new(chart.Lock) | ||
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil { | ||
return c, errors.Wrap(err, "cannot load requirements.lock") | ||
} | ||
if c.Metadata.APIVersion == chart.APIVersionV1 { | ||
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) | ||
} | ||
|
||
case strings.HasPrefix(f.Name, "templates/"): | ||
c.Templates = append(c.Templates, &chart.File{Name: f.Name, Data: f.Data}) | ||
case strings.HasPrefix(f.Name, "charts/"): | ||
if !p.NoDeps { | ||
if filepath.Ext(f.Name) == ".prov" { | ||
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) | ||
continue | ||
} | ||
fname := strings.TrimPrefix(f.Name, "charts/") | ||
cname := strings.SplitN(fname, "/", 2)[0] | ||
subcharts[cname] = append(subcharts[cname], &loader.BufferedFile{Name: fname, Data: f.Data}) | ||
} | ||
|
||
default: | ||
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) | ||
} | ||
} | ||
|
||
if err := c.Validate(); err != nil { | ||
return c, err | ||
} | ||
|
||
for n, files := range subcharts { | ||
var sc *chart.Chart | ||
var err error | ||
switch { | ||
case strings.IndexAny(n, "_.") == 0: | ||
continue | ||
case filepath.Ext(n) == ".tgz": | ||
file := files[0] | ||
if file.Name != n { | ||
return c, errors.Errorf("error unpacking tar in %s: expected %s, got %s", c.Name(), n, file.Name) | ||
} | ||
// Untar the chart and add to c.Dependencies | ||
sc, err = loader.LoadArchive(bytes.NewBuffer(file.Data)) | ||
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([]*loader.BufferedFile, 0, len(files)) | ||
for _, f := range files { | ||
parts := strings.SplitN(f.Name, "/", 2) | ||
if len(parts) < 2 { | ||
continue | ||
} | ||
f.Name = parts[1] | ||
buff = append(buff, f) | ||
} | ||
sc, err = LoadFiles(buff, p) | ||
} | ||
|
||
if err != nil { | ||
return c, errors.Wrapf(err, "error unpacking %s in %s", n, c.Name()) | ||
} | ||
c.AddDependency(sc) | ||
} | ||
|
||
return c, nil | ||
} |
Oops, something went wrong.