diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 855fe24b4..f529f8ce5 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -96,7 +96,7 @@ func (l *lintCmd) run() error { var total int var failures int for _, path := range l.paths { - if linter, err := lintChart(path, rvals, l.namespace); err != nil { + if linter, err := lintChart(path, rvals, l.namespace, l.strict); err != nil { fmt.Println("==> Skipping", path) fmt.Println(err) } else { @@ -128,7 +128,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{} @@ -160,7 +160,7 @@ func lintChart(path string, vals []byte, namespace string) (support.Linter, erro return linter, errLintNoChart } - return lint.All(chartPath, vals, namespace), nil + return lint.All(chartPath, vals, namespace, strict), nil } func (l *lintCmd) vals() ([]byte, error) { diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go index 3ef1e4b71..e52bdc056 100644 --- a/cmd/helm/lint_test.go +++ b/cmd/helm/lint_test.go @@ -23,16 +23,17 @@ import ( var ( values = []byte{} namespace = "testNamespace" + strict = false archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz" chartDirPath = "testdata/testcharts/decompressedchart/" ) func TestLintChart(t *testing.T) { - if _, err := lintChart(chartDirPath, values, namespace); err != nil { + if _, err := lintChart(chartDirPath, values, namespace, strict); err != nil { t.Errorf("%s", err) } - if _, err := lintChart(archivedChartPath, values, namespace); err != nil { + if _, err := lintChart(archivedChartPath, values, namespace, strict); err != nil { t.Errorf("%s", err) } diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index 58a570a7b..256eab906 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 9c7da821e..d84faa10b 100644 --- a/pkg/lint/lint_test.go +++ b/pkg/lint/lint_test.go @@ -27,6 +27,7 @@ import ( var values = []byte{} const namespace = "testNamespace" +const strict = false const badChartDir = "rules/testdata/badchartfile" const badValuesFileDir = "rules/testdata/badvaluesfile" @@ -34,7 +35,7 @@ const badYamlFileDir = "rules/testdata/albatross" const goodChartDir = "rules/testdata/goodone" func TestBadChart(t *testing.T) { - m := All(badChartDir, values, namespace).Messages + m := All(badChartDir, values, namespace, strict).Messages if len(m) != 5 { t.Errorf("Number of errors %v", len(m)) t.Errorf("All didn't fail with expected errors, got %#v", m) @@ -70,7 +71,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) } @@ -80,7 +81,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) } @@ -90,7 +91,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) } diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 5bf786295..260259282 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) @@ -75,7 +75,11 @@ func Templates(linter *support.Linter, values []byte, namespace string) { //linter.RunLinterRule(support.ErrorSev, err) return } - renderedContentMap, err := engine.New().Render(chart, valuesToRender) + e := engine.New() + if strict { + e.Strict = true + } + renderedContentMap, err := e.Render(chart, valuesToRender) renderOk := linter.RunLinterRule(support.ErrorSev, path, err) diff --git a/pkg/lint/rules/template_test.go b/pkg/lint/rules/template_test.go index 47f6cbdc1..080064698 100644 --- a/pkg/lint/rules/template_test.go +++ b/pkg/lint/rules/template_test.go @@ -47,10 +47,11 @@ func TestValidateAllowedExtension(t *testing.T) { var values = []byte("nameOverride: ''\nhttpPort: 80") const namespace = "testNamespace" +const strict = false 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 { @@ -73,7 +74,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 {