Update values.yaml linting to respect value options flags

Previously, the lint command ignored values passed via value options
flags when linting a chart's values.yaml file. This was problematic
because such values are often required when validating against JSON
schema

Closes #7273

Signed-off-by: Robbie deMuth <robbie.demuth@appian.com>
pull/7417/head
Robbie deMuth 6 years ago
parent c08daeca5f
commit 779f42f558

@ -0,0 +1,38 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"testing"
)
func TestLintCmd(t *testing.T) {
chart := "testdata/testcharts/chart-with-schema-negative"
tests := []cmdTestCase{
{
name: "check fails without value option flags",
cmd: fmt.Sprintf("lint %s", chart),
wantError: true,
},
{
name: "check passes with value option flags",
cmd: fmt.Sprintf("lint %s --set age=25,employmentInfo.salary=100000", chart),
},
}
runTestCmd(t, tests)
}

@ -30,7 +30,7 @@ func All(basedir string, values map[string]interface{}, namespace string, strict
linter := support.Linter{ChartDir: chartDir} linter := support.Linter{ChartDir: chartDir}
rules.Chartfile(&linter) rules.Chartfile(&linter)
rules.Values(&linter) rules.Values(&linter, values)
rules.Templates(&linter, values, namespace, strict) rules.Templates(&linter, values, namespace, strict)
return linter return linter
} }

@ -28,7 +28,7 @@ import (
) )
// Values lints a chart's values.yaml file. // Values lints a chart's values.yaml file.
func Values(linter *support.Linter) { func Values(linter *support.Linter, values map[string]interface{}) {
file := "values.yaml" file := "values.yaml"
vf := filepath.Join(linter.ChartDir, file) vf := filepath.Join(linter.ChartDir, file)
fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(vf)) fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(vf))
@ -37,7 +37,7 @@ func Values(linter *support.Linter) {
return return
} }
linter.RunLinterRule(support.ErrorSev, file, validateValuesFile(vf)) linter.RunLinterRule(support.ErrorSev, file, validateValues(vf, values))
} }
func validateValuesFileExistence(valuesPath string) error { func validateValuesFileExistence(valuesPath string) error {
@ -48,8 +48,8 @@ func validateValuesFileExistence(valuesPath string) error {
return nil return nil
} }
func validateValuesFile(valuesPath string) error { func validateValues(valuesPath string, values map[string]interface{}) error {
values, err := chartutil.ReadValuesFile(valuesPath) fv, err := chartutil.ReadValuesFile(valuesPath)
if err != nil { if err != nil {
return errors.Wrap(err, "unable to parse YAML") return errors.Wrap(err, "unable to parse YAML")
} }
@ -63,5 +63,5 @@ func validateValuesFile(valuesPath string) error {
if err != nil { if err != nil {
return err return err
} }
return chartutil.ValidateAgainstSingleSchema(values, schema) return chartutil.ValidateAgainstSingleSchema(chartutil.CoalesceTables(values, fv), schema)
} }

Loading…
Cancel
Save