From 3ea2ff4a5a8a179833f8f70278cff24d0968642a Mon Sep 17 00:00:00 2001 From: Wil Reichert Date: Thu, 15 Jun 2017 20:17:02 +0900 Subject: [PATCH] enable schema validation check --- pkg/lint/rules/template.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 73206b80c..b686a833e 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/version" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/engine" + "k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/lint/support" "k8s.io/helm/pkg/timeconv" tversion "k8s.io/helm/pkg/version" @@ -116,6 +117,27 @@ func Templates(linter *support.Linter) { if !validYaml { continue } + + // access kubectl client + kubeClient := kube.New(kube.GetConfig("")) + f := kubeClient.Factory + + // get the schema validator + schema, err := f.Validator(true, kubeClient.SchemaCacheDir) + if err != nil { + panic(err) + } + + // convert to YAML to JSON, validated above so should be ok + j, _ := yaml.YAMLToJSON([]byte(renderedContent)) + + // + err = schema.ValidateBytes(j) + validSchema := linter.RunLinterRule(support.ErrorSev, path, validateSchema(err)) + + if !validSchema { + continue + } } } @@ -149,6 +171,13 @@ func validateYamlContent(err error) error { return nil } +func validateSchema(err error) error { + if err != nil { + return fmt.Errorf("schema validation failure - %s", err) + } + return nil +} + // K8sYamlStruct stubs a Kubernetes YAML file. // Need to access for now to Namespace only type K8sYamlStruct struct {