Return early when linting if the `templates/` dir does not exist

The `vaildateTemplatesDir` function would still return `nil` if the directory doesn't exist,
so the early return that was documented never occurs.

Signed-off-by: Zach Burgess <zachburg@google.com>
pull/31019/head
Zach Burgess 3 months ago
parent ca769df369
commit b703d5b4bb

@ -1,6 +1,5 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended
[ERROR] templates/: error unpacking subchart bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[ERROR] : unable to load chart
error unpacking subchart bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
@ -9,7 +8,6 @@
[ERROR] Chart.yaml: apiVersion is required. The value must be either "v1" or "v2"
[ERROR] Chart.yaml: version is required
[INFO] Chart.yaml: icon is recommended
[ERROR] templates/: validation: chart.metadata.name is required
[ERROR] : unable to load chart
validation: chart.metadata.name is required

@ -1,6 +1,5 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended
[ERROR] templates/: error unpacking subchart bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[ERROR] : unable to load chart
error unpacking subchart bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required

@ -1,7 +1,6 @@
==> Linting testdata/testcharts/chart-bad-requirements
[ERROR] Chart.yaml: unable to parse YAML
error converting YAML to JSON: yaml: line 6: did not find expected '-' indicator
[ERROR] templates/: cannot load Chart.yaml: error converting YAML to JSON: yaml: line 6: did not find expected '-' indicator
[ERROR] : unable to load chart
cannot load Chart.yaml: error converting YAML to JSON: yaml: line 6: did not find expected '-' indicator

@ -39,7 +39,7 @@ const invalidChartFileDir = "rules/testdata/invalidchartfile"
func TestBadChart(t *testing.T) {
m := RunAll(badChartDir, values, namespace).Messages
if len(m) != 8 {
if len(m) != 7 {
t.Errorf("Number of errors %v", len(m))
t.Errorf("All didn't fail with expected errors, got %#v", m)
}

@ -54,13 +54,13 @@ func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string
fpath := "templates/"
templatesPath := filepath.Join(linter.ChartDir, fpath)
templatesDirExist := linter.RunLinterRule(support.WarningSev, fpath, validateTemplatesDir(templatesPath))
// Templates directory is optional for now
if !templatesDirExist {
if _, err := os.Stat(templatesPath); errors.Is(err, os.ErrNotExist) {
return
}
linter.RunLinterRule(support.WarningSev, fpath, validateTemplatesDir(templatesPath))
// Load chart and parse templates
chart, err := loader.Load(linter.ChartDir)
@ -195,10 +195,12 @@ func validateTopIndentLevel(content string) error {
// Validation functions
func validateTemplatesDir(templatesPath string) error {
if fi, err := os.Stat(templatesPath); err == nil {
if !fi.IsDir() {
return errors.New("not a directory")
}
fi, err := os.Stat(templatesPath)
if err != nil {
return err
}
if !fi.IsDir() {
return errors.New("not a directory")
}
return nil
}

Loading…
Cancel
Save