diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 50790b016b2..c52b23c78e7 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -97,7 +97,7 @@ func (l *lintCmd) run() error { var total int var failures int for _, path := range l.paths { - linter, err := lintChart(path, rvals, l.namespace) + linter, err := lintChart(path, rvals, l.namespace, l.strict) if err != nil { failures = failures + 1 fmt.Println("==> Skipping", path) @@ -132,7 +132,7 @@ func (l *lintCmd) run() error { return nil } -func lintChart(path string, vals []byte, namespace string) (support.Linter, error) { +func lintChart(path string, vals []byte, namespace string, strict bool) (support.Linter, error) { var chartPath string linter := support.Linter{} @@ -171,7 +171,7 @@ func lintChart(path string, vals []byte, namespace string) (support.Linter, erro return linter, fmt.Errorf("unable to check Chart.yaml file in chart: %s", err.Error()) } - return lint.All(chartPath, vals, namespace), nil + return lint.All(chartPath, vals, namespace, strict), nil } // vals merges values from files specified via -f/--values and diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go index 097365bb66c..7f68ad99f9f 100644 --- a/cmd/helm/lint_test.go +++ b/cmd/helm/lint_test.go @@ -58,10 +58,11 @@ func TestLintChart(t *testing.T) { values := []byte{} namespace := "testNamespace" + strict := false for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := lintChart(tt.chartPath, values, namespace) + _, err := lintChart(tt.chartPath, values, namespace, strict) switch { case err != nil && !tt.err: t.Errorf("%s", err) diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index d1a3b1c70cf..aa8df58143f 100644 --- a/pkg/lint/lint.go +++ b/pkg/lint/lint.go @@ -24,13 +24,13 @@ import ( ) // All runs all of the available linters on the given base directory. -func All(basedir string, values []byte, namespace string) support.Linter { +func All(basedir string, values []byte, namespace string, strict bool) support.Linter { // Using abs path to get directory context chartDir, _ := filepath.Abs(basedir) linter := support.Linter{ChartDir: chartDir} rules.Chartfile(&linter) rules.Values(&linter) - rules.Templates(&linter, values, namespace) + rules.Templates(&linter, values, namespace, strict) return linter } diff --git a/pkg/lint/lint_test.go b/pkg/lint/lint_test.go index 33edc976d8a..2c050fa21a6 100644 --- a/pkg/lint/lint_test.go +++ b/pkg/lint/lint_test.go @@ -31,6 +31,7 @@ var values = []byte{} const ( namespace = "testNamespace" + strict = false badChartDir = "rules/testdata/badchartfile" badValuesFileDir = "rules/testdata/badvaluesfile" badYamlFileDir = "rules/testdata/albatross" @@ -38,7 +39,7 @@ const ( ) func TestBadChart(t *testing.T) { - m := All(badChartDir, values, namespace).Messages + m := All(badChartDir, values, namespace, strict).Messages if len(m) != 6 { t.Errorf("Number of errors %v", len(m)) t.Errorf("All didn't fail with expected errors, got %#v", m) @@ -78,7 +79,7 @@ func TestBadChart(t *testing.T) { } func TestInvalidYaml(t *testing.T) { - m := All(badYamlFileDir, values, namespace).Messages + m := All(badYamlFileDir, values, namespace, strict).Messages if len(m) != 1 { t.Fatalf("All didn't fail with expected errors, got %#v", m) } @@ -88,7 +89,7 @@ func TestInvalidYaml(t *testing.T) { } func TestBadValues(t *testing.T) { - m := All(badValuesFileDir, values, namespace).Messages + m := All(badValuesFileDir, values, namespace, strict).Messages if len(m) != 1 { t.Fatalf("All didn't fail with expected errors, got %#v", m) } @@ -98,7 +99,7 @@ func TestBadValues(t *testing.T) { } func TestGoodChart(t *testing.T) { - m := All(goodChartDir, values, namespace).Messages + m := All(goodChartDir, values, namespace, strict).Messages if len(m) != 0 { t.Errorf("All failed but shouldn't have: %#v", m) } @@ -129,7 +130,7 @@ func TestHelmCreateChart(t *testing.T) { return } - m := All(createdChart, values, namespace).Messages + m := All(createdChart, values, namespace, strict).Messages if ll := len(m); ll != 1 { t.Errorf("All should have had exactly 1 error. Got %d", ll) } else if msg := m[0].Err.Error(); !strings.Contains(msg, "icon is recommended") { diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index ab3f154ef71..f494540df77 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -32,7 +32,7 @@ import ( ) // Templates lints the templates in the Linter. -func Templates(linter *support.Linter, values []byte, namespace string) { +func Templates(linter *support.Linter, values []byte, namespace string, strict bool) { path := "templates/" templatesPath := filepath.Join(linter.ChartDir, path) diff --git a/pkg/lint/rules/template_test.go b/pkg/lint/rules/template_test.go index 23a7fc4ae0f..5e29131389e 100644 --- a/pkg/lint/rules/template_test.go +++ b/pkg/lint/rules/template_test.go @@ -55,7 +55,7 @@ var values = []byte("nameOverride: ''\nhttpPort: 80") func TestTemplateParsing(t *testing.T) { linter := support.Linter{ChartDir: templateTestBasedir} - Templates(&linter, values, namespace) + Templates(&linter, values, namespace, strict) res := linter.Messages if len(res) != 1 { @@ -78,7 +78,7 @@ func TestTemplateIntegrationHappyPath(t *testing.T) { defer os.Rename(ignoredTemplatePath, wrongTemplatePath) linter := support.Linter{ChartDir: templateTestBasedir} - Templates(&linter, values, namespace) + Templates(&linter, values, namespace, strict) res := linter.Messages if len(res) != 0 { @@ -112,6 +112,7 @@ data: myval1: {{default "val" .Values.mymap.key1 }} myval2: {{default "val" .Values.mymap.key2 }} ` + var ingoredStrict = true ch := chart.Chart{ Metadata: &chart.Metadata{ Name: "regression.6705", @@ -132,7 +133,7 @@ data: linter := &support.Linter{ ChartDir: filepath.Join(dir, ch.Metadata.Name), } - Templates(linter, vals, namespace) + Templates(linter, vals, namespace, ingoredStrict) if len(linter.Messages) != 0 { t.Errorf("expected zero messages, got %d", len(linter.Messages)) for i, msg := range linter.Messages {