Skip to content

Commit

Permalink
Remove warning for template directory not found.
Browse files Browse the repository at this point in the history
Some charts don't need a templates directory. The warning appears to originate back when helm expected all charts to contain templates. In CI situations where linting is performed with --strict the lint warning causes unneccessary failures for charts that quite legitimately do not contain a templates directory.

As discussed in #8033 there are no longer any scenarios understood where this warning is helpful so this commit removes it.

Signed-off-by: James Blair <mail@jamesblair.net>
  • Loading branch information
jmhbnz committed Jul 9, 2023
1 parent f31d4fb commit 9dab6e9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
@@ -1,6 +1,6 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory not found
[ERROR] templates/: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[ERROR] : unable to load chart
error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required

Expand All @@ -9,12 +9,11 @@
[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 not found
[ERROR] templates/: validation: chart.metadata.name is required
[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 not found

Error: 3 chart(s) linted, 2 chart(s) failed
2 changes: 1 addition & 1 deletion cmd/helm/testdata/output/lint-chart-with-bad-subcharts.txt
@@ -1,6 +1,6 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts
[INFO] Chart.yaml: icon is recommended
[WARNING] templates/: directory not found
[ERROR] templates/: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[ERROR] : unable to load chart
error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required

Expand Down
2 changes: 1 addition & 1 deletion cmd/helm/testdata/output/lint-quiet-with-error.txt
@@ -1,7 +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 not found
[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

Expand Down
4 changes: 0 additions & 4 deletions cmd/helm/testdata/output/lint-quiet-with-warning.txt
@@ -1,4 +0,0 @@
==> Linting testdata/testcharts/chart-with-only-crds
[WARNING] templates/: directory not found

1 chart(s) linted, 0 chart(s) failed
6 changes: 3 additions & 3 deletions pkg/action/lint_test.go
Expand Up @@ -149,12 +149,12 @@ func TestLint_ChartWithWarnings(t *testing.T) {
}
})

t.Run("should fail with errors when strict", func(t *testing.T) {
t.Run("should pass with no errors when strict", func(t *testing.T) {
testCharts := []string{chartWithNoTemplatesDir}
testLint := NewLint()
testLint.Strict = true
if result := testLint.Run(testCharts, values); len(result.Errors) != 1 {
t.Error("expected one error, but got", len(result.Errors))
if result := testLint.Run(testCharts, values); len(result.Errors) != 0 {
t.Error("expected no errors, but got", len(result.Errors))
}
})
}
11 changes: 3 additions & 8 deletions pkg/lint/lint_test.go
Expand Up @@ -43,19 +43,14 @@ func TestBadChart(t *testing.T) {
t.Errorf("Number of errors %v", len(m))
t.Errorf("All didn't fail with expected errors, got %#v", m)
}
// There should be one INFO, 2 WARNINGs and 2 ERROR messages, check for them
var i, w, e, e2, e3, e4, e5, e6 bool
// There should be one INFO, and 2 ERROR messages, check for them
var i, e, e2, e3, e4, e5, e6 bool
for _, msg := range m {
if msg.Severity == support.InfoSev {
if strings.Contains(msg.Err.Error(), "icon is recommended") {
i = true
}
}
if msg.Severity == support.WarningSev {
if strings.Contains(msg.Err.Error(), "directory not found") {
w = true
}
}
if msg.Severity == support.ErrorSev {
if strings.Contains(msg.Err.Error(), "version '0.0.0.0' is not a valid SemVer") {
e = true
Expand All @@ -81,7 +76,7 @@ func TestBadChart(t *testing.T) {
}
}
}
if !e || !e2 || !e3 || !e4 || !e5 || !w || !i || !e6 {
if !e || !e2 || !e3 || !e4 || !e5 || !i || !e6 {
t.Errorf("Didn't find all the expected errors, got %#v", m)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/lint/rules/template.go
Expand Up @@ -188,10 +188,10 @@ func validateTopIndentLevel(content string) error {

// Validation functions
func validateTemplatesDir(templatesPath string) error {
if fi, err := os.Stat(templatesPath); err != nil {
return errors.New("directory not found")
} else if !fi.IsDir() {
return errors.New("not a directory")
if fi, err := os.Stat(templatesPath); err == nil {
if !fi.IsDir() {
return errors.New("not a directory")
}
}
return nil
}
Expand Down

0 comments on commit 9dab6e9

Please sign in to comment.