From 2a35b6864c945c131768fe7ad2cb9f4c0adb9726 Mon Sep 17 00:00:00 2001 From: Eric Chin Date: Mon, 10 Dec 2018 16:54:57 -0500 Subject: [PATCH] Remove extra appending of chartName for lint and template (#406) Closes #407 --- state/state.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/state/state.go b/state/state.go index eb8bc85e..b1e4c7bd 100644 --- a/state/state.go +++ b/state/state.go @@ -7,6 +7,7 @@ import ( "os" "path" "path/filepath" + "sort" "strconv" "strings" "sync" @@ -385,8 +386,13 @@ func (state *HelmState) downloadCharts(helm helmexec.Interface, dir string, work errs = append(errs, err) } } - chartPath = path.Join(chartPath, chartNameWithoutRepository(release.Chart)) + // Set chartPath to be the path containing Chart.yaml, if found + fullChartPath, err := findChartDirectory(chartPath) + if err == nil { + chartPath = filepath.Dir(fullChartPath) + } } + results <- &downloadResults{release.Name, chartPath} } wgFetch.Done() @@ -968,6 +974,28 @@ func chartNameWithoutRepository(chart string) string { return chartSplit[len(chartSplit)-1] } +// find "Chart.yaml" +func findChartDirectory(topLevelDir string) (string, error) { + var files []string + filepath.Walk(topLevelDir, func(path string, f os.FileInfo, _ error) error { + if !f.IsDir() { + r, err := regexp.MatchString("Chart.yaml", f.Name()) + if err == nil && r { + files = append(files, path) + } + } + return nil + }) + // Sort to get the shortest path + sort.Strings(files) + if len(files) > 0 { + first := files[0] + return first, nil + } + + return topLevelDir, errors.New("No Chart.yaml found") +} + func (state *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSpec) ([]string, error) { flags := []string{} if release.Version != "" {