Return a lint warning if `templates/` does not exist.

Signed-off-by: Zach Burgess <zachburg@google.com>
pull/31019/head
Zach Burgess 2 months ago
parent b6e3301bef
commit 35434947a3

@ -154,12 +154,12 @@ func TestLint_ChartWithWarnings(t *testing.T) {
}
})
t.Run("should pass with no errors when strict", func(t *testing.T) {
t.Run("should fail with one error when strict", func(t *testing.T) {
testCharts := []string{chartWithNoTemplatesDir}
testLint := NewLint()
testLint.Strict = true
if result := testLint.Run(testCharts, values); len(result.Errors) != 0 {
t.Error("expected no errors, but got", len(result.Errors))
if result := testLint.Run(testCharts, values); len(result.Errors) != 1 {
t.Error("expected one error, but got", len(result.Errors))
}
})
}

@ -1,5 +1,6 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory does not exist
[ERROR] : unable to load chart
error unpacking subchart bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
@ -8,10 +9,12 @@
[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
[WARNING] templates/: directory does not exist
[ERROR] : unable to load chart
validation: chart.metadata.name is required
==> Linting testdata/testcharts/chart-with-bad-subcharts/charts/good-subchart
[INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory does not exist
Error: 3 chart(s) linted, 2 chart(s) failed

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

@ -1,6 +1,7 @@
==> 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
[WARNING] templates/: directory does not exist
[ERROR] : unable to load chart
cannot load Chart.yaml: error converting YAML to JSON: yaml: line 6: did not find expected '-' indicator

@ -0,0 +1,4 @@
==> Linting testdata/testcharts/chart-with-only-crds
[WARNING] templates/: directory does not exist
1 chart(s) linted, 0 chart(s) failed

@ -55,7 +55,8 @@ func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string
templatesPath := filepath.Join(linter.ChartDir, fpath)
// Templates directory is optional for now
if _, err := os.Stat(templatesPath); errors.Is(err, os.ErrNotExist) {
templatesDirExists := linter.RunLinterRule(support.WarningSev, fpath, templatesDirExists(templatesPath))
if !templatesDirExists {
return
}
@ -197,6 +198,14 @@ func validateTopIndentLevel(content string) error {
}
// Validation functions
func templatesDirExists(templatesPath string) error {
_, err := os.Stat(templatesPath)
if errors.Is(err, os.ErrNotExist) {
return errors.New("directory does not exist")
}
return nil
}
func validateTemplatesDir(templatesPath string) error {
fi, err := os.Stat(templatesPath)
if err != nil {

Loading…
Cancel
Save