diff --git a/pkg/action/lint_test.go b/pkg/action/lint_test.go index c442be344..eec9f9533 100644 --- a/pkg/action/lint_test.go +++ b/pkg/action/lint_test.go @@ -29,6 +29,8 @@ var ( invalidArchivedChartPath = "../../cmd/helm/testdata/testcharts/invalidcompressedchart0.1.0.tgz" chartDirPath = "../../cmd/helm/testdata/testcharts/decompressedchart/" 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" ) func TestLintChart(t *testing.T) { @@ -47,4 +49,10 @@ func TestLintChart(t *testing.T) { if _, err := lintChart(chartMissingManifest, values, namespace, strict); err == nil { t.Error("Expected a chart parsing error") } + if _, err := lintChart(chartSchema, values, namespace, strict); err != nil { + t.Error(err) + } + if _, err := lintChart(chartSchemaNegative, values, namespace, strict); err != nil { + t.Error(err) + } } diff --git a/pkg/lint/rules/values.go b/pkg/lint/rules/values.go index f3d9a7317..3cc209094 100644 --- a/pkg/lint/rules/values.go +++ b/pkg/lint/rules/values.go @@ -19,6 +19,7 @@ package rules import ( "os" "path/filepath" + "strings" "github.com/pkg/errors" @@ -48,6 +49,18 @@ func validateValuesFileExistence(valuesPath string) error { } func validateValuesFile(valuesPath string) error { - _, err := chartutil.ReadValuesFile(valuesPath) - return errors.Wrap(err, "unable to parse YAML") + values, err := chartutil.ReadValuesFile(valuesPath) + if err != nil { + return errors.Wrap(err, "unable to parse YAML") + } + + schemaPath := strings.Replace(valuesPath, ".yaml", ".schema.yaml", 1) + schema, err := chartutil.ReadSchemaFile(schemaPath) + if len(schema) == 0 { + return nil + } + if err != nil { + return err + } + return chartutil.ValidateAgainstSchema(values, schema) }