WIP fix(helm): Add processing of global helmignore file

In addition to processing helmignore file located in the current
directory, this patch adds processing of the global helmignore located
in helm's client default location.

Closes #1674
pull/2038/head
Serguei Bezverkhi 9 years ago
parent 9c8357ac3c
commit 8494fa11af

@ -138,6 +138,19 @@ func newRootCmd(out io.Writer) *cobra.Command {
// Find and add plugins // Find and add plugins
loadPlugins(cmd, helmpath.Home(homePath()), out) loadPlugins(cmd, helmpath.Home(homePath()), out)
// Load helmignore file, BuildIgnoreFiles will find helm client location
// for global ignore file, but it needs a current folder location to check
// for local helmignore file.
// ignoreFiles := BuildIgnoreFiles(func() string {
BuildIgnoreFiles(func() string {
// Need to figure out how to get working path
topdir, err := filepath.Abs("./")
if err == nil {
topdir += string(filepath.Separator)
}
return topdir
}())
return cmd return cmd
} }

@ -31,6 +31,7 @@ import (
"k8s.io/helm/cmd/helm/helmpath" "k8s.io/helm/cmd/helm/helmpath"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/ignore"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/provenance" "k8s.io/helm/pkg/provenance"
"k8s.io/helm/pkg/repo" "k8s.io/helm/pkg/repo"
@ -198,3 +199,28 @@ func promptUser(name string) ([]byte, error) {
fmt.Println() fmt.Println()
return pw, err return pw, err
} }
// BuildIgnoreFiles loads global helmignore file if it exists and
// helmignore file from the current folder into a slice of strings.
func BuildIgnoreFiles(dir string) []string {
ignoreFiles := []string{}
topdir, err := filepath.Abs(dir)
if err == nil {
topdir += string(filepath.Separator)
f, err := os.Open(topdir + ignore.HelmIgnore)
if err == nil {
defer f.Close()
ignoreFiles = append(ignoreFiles, topdir+ignore.HelmIgnore)
}
}
homeDir := fmt.Sprintf("%s", helmpath.Home(homePath()))
f, err := os.Open(homeDir + ignore.HelmIgnore)
if err == nil {
defer f.Close()
ignoreFiles = append(ignoreFiles, topdir+ignore.HelmIgnore)
}
return ignoreFiles
}

@ -214,10 +214,25 @@ func LoadFile(name string) (*chart.Chart, error) {
return LoadArchive(raw) return LoadArchive(raw)
} }
// LoadIgnoreFiles loads helmignore files and returns a reader.
func LoadIgnoreFiles(ignoreFiles []string) *bytes.Reader {
buff := bytes.NewBuffer(nil)
for _, ignf := range ignoreFiles {
f, err := os.Open(ignf)
if err == nil {
defer f.Close()
io.Copy(buff, f)
}
}
return bytes.NewReader(buff.Bytes())
}
// LoadDir loads from a directory. // LoadDir loads from a directory.
// //
// This loads charts only from directories. // This loads charts only from directories.
func LoadDir(dir string) (*chart.Chart, error) { func LoadDir(dir string, ignoreFiles ...string) (*chart.Chart, error) {
topdir, err := filepath.Abs(dir) topdir, err := filepath.Abs(dir)
if err != nil { if err != nil {
return nil, err return nil, err
@ -227,13 +242,12 @@ func LoadDir(dir string) (*chart.Chart, error) {
c := &chart.Chart{} c := &chart.Chart{}
rules := ignore.Empty() rules := ignore.Empty()
ifile := filepath.Join(topdir, ignore.HelmIgnore) r := LoadIgnoreFiles(ignoreFiles)
if _, err := os.Stat(ifile); err == nil { if r.Len() > 0 {
r, err := ignore.ParseFile(ifile) rules, err = ignore.Parse(r)
if err != nil { if err != nil {
return c, err return c, err
} }
rules = r
} }
rules.AddDefaults() rules.AddDefaults()

Loading…
Cancel
Save