Merge pull request #6241 from waveywaves/fix/issue-6079

Clone the vals map for every path to avoid mutation
pull/6282/head
Taylor Thomas 5 years ago committed by GitHub
commit 7466c4ee3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,4 @@
apiVersion: v1
name: multiplecharts-lint-chart-1
version: 1
icon: ""

@ -0,0 +1,6 @@
apiVersion: v1
metadata:
name: multicharttest-chart1-configmap
data:
dat: |
{{ .Values.config | indent 4 }}

@ -0,0 +1,4 @@
apiVersion: v1
name: multiplecharts-lint-chart-2
version: 1
icon: ""

@ -0,0 +1,5 @@
apiVersion: v1
metadata:
name: multicharttest-chart2-configmap
data:
{{ toYaml .Values.config | indent 4 }}

@ -59,15 +59,22 @@ func (l *Lint) Run(paths []string, vals map[string]interface{}) *LintResult {
result := &LintResult{}
for _, path := range paths {
if linter, err := lintChart(path, vals, l.Namespace, l.Strict); err != nil {
linter, err := lintChart(path, vals, l.Namespace, l.Strict)
if err != nil {
if err == errLintNoChart {
result.Errors = append(result.Errors, err)
}
if linter.HighestSeverity >= lowestTolerance {
result.Errors = append(result.Errors, err)
}
} else {
result.Messages = append(result.Messages, linter.Messages...)
result.TotalChartsLinted++
if linter.HighestSeverity >= lowestTolerance {
result.Errors = append(result.Errors, err)
for _, msg := range linter.Messages {
if msg.Severity == support.ErrorSev {
result.Errors = append(result.Errors, msg.Err)
result.Messages = append(result.Messages, msg)
}
}
}
}
@ -77,6 +84,10 @@ func (l *Lint) Run(paths []string, vals map[string]interface{}) *LintResult {
func lintChart(path string, vals map[string]interface{}, namespace string, strict bool) (support.Linter, error) {
var chartPath string
linter := support.Linter{}
currentVals := make(map[string]interface{}, len(vals))
for key, value := range vals {
currentVals[key] = value
}
if strings.HasSuffix(path, ".tgz") {
tempDir, err := ioutil.TempDir("", "helm-lint")
@ -110,5 +121,5 @@ func lintChart(path string, vals map[string]interface{}, namespace string, stric
return linter, errLintNoChart
}
return lint.All(chartPath, vals, namespace, strict), nil
return lint.All(chartPath, currentVals, namespace, strict), nil
}

@ -31,6 +31,8 @@ var (
chartMissingManifest = "../../cmd/helm/testdata/testcharts/chart-missing-manifest"
chartSchema = "../../cmd/helm/testdata/testcharts/chart-with-schema"
chartSchemaNegative = "../../cmd/helm/testdata/testcharts/chart-with-schema-negative"
chart1MultipleChartLint = "../../cmd/helm/testdata/testcharts/multiplecharts-lint-chart-1"
chart2MultipleChartLint = "../../cmd/helm/testdata/testcharts/multiplecharts-lint-chart-2"
)
func TestLintChart(t *testing.T) {
@ -56,3 +58,19 @@ func TestLintChart(t *testing.T) {
t.Error(err)
}
}
func TestLint_MultipleCharts(t *testing.T) {
testCharts := []string{chart2MultipleChartLint, chart1MultipleChartLint}
testLint := NewLint()
if result := testLint.Run(testCharts, values); len(result.Errors) > 0 {
t.Error(result.Errors)
}
}
func TestLint_EmptyResultErrors(t *testing.T) {
testCharts := []string{chart2MultipleChartLint}
testLint := NewLint()
if result := testLint.Run(testCharts, values); len(result.Errors) > 0 {
t.Error("Expected no error, got more")
}
}

@ -61,9 +61,7 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
}
valuesToRender, err := chartutil.ToRenderValues(chart, cvals, options, nil)
if err != nil {
// FIXME: This seems to generate a duplicate, but I can't find where the first
// error is coming from.
//linter.RunLinterRule(support.ErrorSev, err)
linter.RunLinterRule(support.ErrorSev, path, err)
return
}
var e engine.Engine

Loading…
Cancel
Save