diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 11d2ff4ab..3862d2d76 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -42,6 +42,7 @@ or recommendation, it will emit [WARNING] messages. ` type lintCmd struct { + namespace string strict bool paths []string out io.Writer @@ -64,6 +65,7 @@ func newLintCmd(out io.Writer) *cobra.Command { }, } + cmd.Flags().StringVar(&l.namespace, "namespace", "default", "namespace to install the release into (only used if --install is set)") cmd.Flags().BoolVar(&l.strict, "strict", false, "fail on lint warnings") return cmd @@ -82,7 +84,7 @@ func (l *lintCmd) run() error { var total int var failures int for _, path := range l.paths { - if linter, err := lintChart(path); err != nil { + if linter, err := lintChart(path, l.namespace); err != nil { fmt.Println("==> Skipping", path) fmt.Println(err) } else { @@ -114,7 +116,7 @@ func (l *lintCmd) run() error { return nil } -func lintChart(path string) (support.Linter, error) { +func lintChart(path string, namespace string) (support.Linter, error) { var chartPath string linter := support.Linter{} @@ -146,5 +148,5 @@ func lintChart(path string) (support.Linter, error) { return linter, errLintNoChart } - return lint.All(chartPath), nil + return lint.All(chartPath, namespace), nil } diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go index 9f71c0231..acf408eaa 100644 --- a/cmd/helm/lint_test.go +++ b/cmd/helm/lint_test.go @@ -21,16 +21,17 @@ import ( ) var ( + namespace = "testNamespace" archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz" chartDirPath = "testdata/testcharts/decompressedchart/" ) func TestLintChart(t *testing.T) { - if _, err := lintChart(chartDirPath); err != nil { + if _, err := lintChart(chartDirPath, namespace); err != nil { t.Errorf("%s", err) } - if _, err := lintChart(archivedChartPath); err != nil { + if _, err := lintChart(archivedChartPath, namespace); err != nil { t.Errorf("%s", err) } diff --git a/pkg/lint/lint.go b/pkg/lint/lint.go index 7903d215c..3debfd926 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) support.Linter { +func All(basedir string, namespace string) 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) + rules.Templates(&linter, namespace) return linter } diff --git a/pkg/lint/lint_test.go b/pkg/lint/lint_test.go index 02040f079..da3edc8db 100644 --- a/pkg/lint/lint_test.go +++ b/pkg/lint/lint_test.go @@ -24,13 +24,15 @@ import ( "testing" ) +const namespace = "testNamespace" + const badChartDir = "rules/testdata/badchartfile" const badValuesFileDir = "rules/testdata/badvaluesfile" const badYamlFileDir = "rules/testdata/albatross" const goodChartDir = "rules/testdata/goodone" func TestBadChart(t *testing.T) { - m := All(badChartDir).Messages + m := All(badChartDir, namespace).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) @@ -66,7 +68,7 @@ func TestBadChart(t *testing.T) { } func TestInvalidYaml(t *testing.T) { - m := All(badYamlFileDir).Messages + m := All(badYamlFileDir, namespace).Messages if len(m) != 1 { t.Fatalf("All didn't fail with expected errors, got %#v", m) } @@ -76,7 +78,7 @@ func TestInvalidYaml(t *testing.T) { } func TestBadValues(t *testing.T) { - m := All(badValuesFileDir).Messages + m := All(badValuesFileDir, namespace).Messages if len(m) != 1 { t.Fatalf("All didn't fail with expected errors, got %#v", m) } @@ -86,7 +88,7 @@ func TestBadValues(t *testing.T) { } func TestGoodChart(t *testing.T) { - m := All(goodChartDir).Messages + m := All(goodChartDir, namespace).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 9343a3a84..c4264e493 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -31,7 +31,7 @@ import ( ) // Templates lints the templates in the Linter. -func Templates(linter *support.Linter) { +func Templates(linter *support.Linter, namespace string) { path := "templates/" templatesPath := filepath.Join(linter.ChartDir, path) @@ -51,7 +51,7 @@ func Templates(linter *support.Linter) { return } - options := chartutil.ReleaseOptions{Name: "testRelease", Time: timeconv.Now(), Namespace: "testNamespace"} + options := chartutil.ReleaseOptions{Name: "testRelease", Time: timeconv.Now(), Namespace: namespace} caps := &chartutil.Capabilities{ APIVersions: chartutil.DefaultVersionSet, KubeVersion: chartutil.DefaultKubeVersion, diff --git a/pkg/lint/rules/template_test.go b/pkg/lint/rules/template_test.go index 5a56e22c9..686dc6a98 100644 --- a/pkg/lint/rules/template_test.go +++ b/pkg/lint/rules/template_test.go @@ -44,9 +44,11 @@ func TestValidateAllowedExtension(t *testing.T) { } } +const namespace = "testNamespace" + func TestTemplateParsing(t *testing.T) { linter := support.Linter{ChartDir: templateTestBasedir} - Templates(&linter) + Templates(&linter, namespace) res := linter.Messages if len(res) != 1 { @@ -69,7 +71,7 @@ func TestTemplateIntegrationHappyPath(t *testing.T) { defer os.Rename(ignoredTemplatePath, wrongTemplatePath) linter := support.Linter{ChartDir: templateTestBasedir} - Templates(&linter) + Templates(&linter, namespace) res := linter.Messages if len(res) != 0 {