Add schema validation to helm lint

Signed-off-by: Ian Howell <ian.howell0@gmail.com>
pull/5350/head
Ian Howell 7 years ago
parent e97ec08992
commit 497be7f5ec

@ -29,6 +29,8 @@ var (
invalidArchivedChartPath = "../../cmd/helm/testdata/testcharts/invalidcompressedchart0.1.0.tgz" invalidArchivedChartPath = "../../cmd/helm/testdata/testcharts/invalidcompressedchart0.1.0.tgz"
chartDirPath = "../../cmd/helm/testdata/testcharts/decompressedchart/" chartDirPath = "../../cmd/helm/testdata/testcharts/decompressedchart/"
chartMissingManifest = "../../cmd/helm/testdata/testcharts/chart-missing-manifest" 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) { func TestLintChart(t *testing.T) {
@ -47,4 +49,10 @@ func TestLintChart(t *testing.T) {
if _, err := lintChart(chartMissingManifest, values, namespace, strict); err == nil { if _, err := lintChart(chartMissingManifest, values, namespace, strict); err == nil {
t.Error("Expected a chart parsing error") 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)
}
} }

@ -19,6 +19,7 @@ package rules
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -48,6 +49,18 @@ func validateValuesFileExistence(valuesPath string) error {
} }
func validateValuesFile(valuesPath string) error { func validateValuesFile(valuesPath string) error {
_, err := chartutil.ReadValuesFile(valuesPath) values, err := chartutil.ReadValuesFile(valuesPath)
if err != nil {
return errors.Wrap(err, "unable to parse YAML") 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)
} }

Loading…
Cancel
Save