fix(helm): allow lint to parse pre-release charts

The lint command cannot parse a compressed chart with a pre-release
version, e.g. 0.1.0-alhpa: it errors out saying it cannot find the
Chart.yaml file. This is due to the way the lint command identifies the
chart dir name, i.e. using the last hyphen in the name of the compressed
file. Changing this method to using the name of the single directory
with the chart's name, as expected from decompressing a chart, allows
lint to parse pre-release charts.

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
pull/5177/head
Arash Deshmeh 7 years ago
parent 2b7221b5b7
commit bfc0d76fff

@ -156,12 +156,15 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support
return linter, err return linter, err
} }
lastHyphenIndex := strings.LastIndex(filepath.Base(path), "-") files, err := ioutil.ReadDir(tempDir)
if lastHyphenIndex <= 0 { if err != nil {
return linter, fmt.Errorf("unable to parse chart archive %q, missing '-'", filepath.Base(path)) return linter, fmt.Errorf("unable to read temporary output directory %s", tempDir)
}
if !files[0].IsDir() {
return linter, fmt.Errorf("unexpected file %s in temporary output directory %s", files[0].Name(), tempDir)
} }
base := filepath.Base(path)[:lastHyphenIndex]
chartPath = filepath.Join(tempDir, base) chartPath = filepath.Join(tempDir, files[0].Name())
} else { } else {
chartPath = path chartPath = path
} }

@ -29,6 +29,7 @@ var (
invalidArchivedChartPath = "testdata/testcharts/invalidcompressedchart0.1.0.tgz" invalidArchivedChartPath = "testdata/testcharts/invalidcompressedchart0.1.0.tgz"
chartDirPath = "testdata/testcharts/decompressedchart/" chartDirPath = "testdata/testcharts/decompressedchart/"
chartMissingManifest = "testdata/testcharts/chart-missing-manifest" chartMissingManifest = "testdata/testcharts/chart-missing-manifest"
chartWithPreReleaseVersion = "testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz"
) )
func TestLintChart(t *testing.T) { func TestLintChart(t *testing.T) {
@ -44,6 +45,10 @@ func TestLintChart(t *testing.T) {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
if _, err := lintChart(chartWithPreReleaseVersion, values, namespace, strict); err != nil {
t.Errorf("%s", err)
}
if _, err := lintChart(invalidArchivedChartPath, values, namespace, strict); err == nil { if _, err := lintChart(invalidArchivedChartPath, values, namespace, strict); err == nil {
t.Errorf("Expected a chart parsing error") t.Errorf("Expected a chart parsing error")
} }

@ -39,6 +39,19 @@ func TestExpand(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
files, err := ioutil.ReadDir(dest)
if err != nil {
t.Fatalf("error reading output directory %s: %s", dest, err)
}
if len(files) != 1 {
t.Fatalf("expected a single chart directory in output directory %s", dest)
}
if !files[0].IsDir() {
t.Fatalf("expected a chart directory in output directory %s", dest)
}
expectedChartPath := filepath.Join(dest, "frobnitz") expectedChartPath := filepath.Join(dest, "frobnitz")
fi, err := os.Stat(expectedChartPath) fi, err := os.Stat(expectedChartPath)
if err != nil { if err != nil {

Loading…
Cancel
Save