Add "--namespace" to helm lint

Keep lint syntax as close as possible to "helm install" resp. "helm
upgrade", so that one only needs to change the command.

See #2036
pull/2972/head
Julian Strobl 8 years ago
parent 0647cdf84c
commit 4aae7cb0d5

@ -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
}

@ -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)
}

@ -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
}

@ -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)
}

@ -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,

@ -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 {

Loading…
Cancel
Save