diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index f4d7e01a..2a90ec9c 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -55,22 +55,18 @@ type Git interface { // // BuildDependencies builds the chart's dependencies // -// Lint runs `helm lint` for the given chart +// LintWithValues runs `helm lint` for the given chart using the specified values file. +// Pass a zero value for valuesFile in order to run lint without specifying a values file. // -// LintWithValues runs `helm lint` for the given chart using the specified values file -// -// Install runs `helm install` for the given chart -// -// InstallWithValues runs `helm install` for the given chart using the specified values file +// InstallWithValues runs `helm install` for the given chart using the specified values file. +// Pass a zero value for valuesFile in order to run install without specifying a values file. // // DeleteRelease purges the specified Helm release. type Helm interface { Init() error AddRepo(name string, url string) error BuildDependencies(chart string) error - Lint(chart string) error LintWithValues(chart string, valuesFile string) error - Install(chart string, namespace string, release string) error InstallWithValues(chart string, valuesFile string, namespace string, release string) error Test(release string) error DeleteRelease(release string) @@ -245,7 +241,7 @@ func (t *Testing) InstallCharts() ([]TestResult, error) { return t.processCharts(t.InstallChart) } -// LintAndInstallChart first lints and then installs charts (changed, all, specific) depending on the configuration. +// LintAndInstallCharts first lints and then installs charts (changed, all, specific) depending on the configuration. func (t *Testing) LintAndInstallCharts() ([]TestResult, error) { return t.processCharts(t.LintAndInstallChart) } @@ -304,16 +300,15 @@ func (t *Testing) LintChart(chart string, valuesFiles []string) TestResult { } } - if len(valuesFiles) > 0 { - for _, valuesFile := range valuesFiles { - if err := t.helm.LintWithValues(chart, valuesFile); err != nil { - result.Error = err - break - } - } - } else { - if err := t.helm.Lint(chart); err != nil { + // Lint with defaults if no values files are specified. + if len(valuesFiles) == 0 { + valuesFiles = append(valuesFiles, "") + } + + for _, valuesFile := range valuesFiles { + if err := t.helm.LintWithValues(chart, valuesFile); err != nil { result.Error = err + break } } diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 96218d37..f9ca9e7d 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -101,12 +101,10 @@ func (l fakeLinter) Yamale(yamlFile, schemaFile string) error { return nil } type fakeHelm struct{} -func (h fakeHelm) Init() error { return nil } -func (h fakeHelm) AddRepo(name, url string) error { return nil } -func (h fakeHelm) BuildDependencies(chart string) error { return nil } -func (h fakeHelm) Lint(chart string) error { return nil } -func (h fakeHelm) LintWithValues(chart string, valuesFile string) error { return nil } -func (h fakeHelm) Install(chart string, namespace string, release string) error { return nil } +func (h fakeHelm) Init() error { return nil } +func (h fakeHelm) AddRepo(name, url string) error { return nil } +func (h fakeHelm) BuildDependencies(chart string) error { return nil } +func (h fakeHelm) LintWithValues(chart string, valuesFile string) error { return nil } func (h fakeHelm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error { return nil } diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index 7c81aeec..9b15537a 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -44,16 +44,13 @@ func (h Helm) BuildDependencies(chart string) error { return h.exec.RunProcess("helm", "dependency", "build", chart) } -func (h Helm) Lint(chart string) error { - return h.exec.RunProcess("helm", "lint", chart) -} - func (h Helm) LintWithValues(chart string, valuesFile string) error { - return h.exec.RunProcess("helm", "lint", chart, "--values", valuesFile) -} + var values []string + if valuesFile != "" { + values = []string{"--values", valuesFile} + } -func (h Helm) Install(chart string, namespace string, release string) error { - return h.InstallWithValues(chart, "", namespace, release) + return h.exec.RunProcess("helm", "lint", chart, values) } func (h Helm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error {