From 50675e7cd748e300f77dcd26f58f6d89886b63b5 Mon Sep 17 00:00:00 2001 From: Simon Alling Date: Fri, 27 Sep 2019 16:27:31 +0200 Subject: [PATCH] fix(pkg/chartutil): include values.schema.json in packaged chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: $ helm lint my-chart # Finds errors in values.yaml $ helm package my-chart $ helm lint my-chart-1.0.0.tgz # Does not find errors in values.yaml Signed-off-by: Simon Alling Co-authored-by: Andreas Lindhé --- pkg/chartutil/create.go | 2 ++ pkg/chartutil/save.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index 7aa78284d..72668ef48 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -35,6 +35,8 @@ const ( ChartfileName = "Chart.yaml" // ValuesfileName is the default values file name. ValuesfileName = "values.yaml" + // SchemafileName is the default values schema file name. + SchemafileName = "values.schema.json" // TemplatesDir is the relative directory name for templates. TemplatesDir = "templates" // ChartsDir is the relative directory name for charts dependencies. diff --git a/pkg/chartutil/save.go b/pkg/chartutil/save.go index 1d90142c1..cf2aad000 100644 --- a/pkg/chartutil/save.go +++ b/pkg/chartutil/save.go @@ -19,6 +19,7 @@ package chartutil import ( "archive/tar" "compress/gzip" + "encoding/json" "fmt" "os" "path/filepath" @@ -56,6 +57,14 @@ func SaveDir(c *chart.Chart, dest string) error { } } + // Save values.schema.json if it exists + if c.Schema != nil { + filename := filepath.Join(outdir, SchemafileName) + if err := writeFile(filename, c.Schema); err != nil { + return err + } + } + // Save templates and files for _, o := range [][]*chart.File{c.Templates, c.Files} { for _, f := range o { @@ -149,6 +158,16 @@ func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error { return err } + // Save values.schema.json if it exists + if c.Schema != nil { + if !json.Valid(c.Schema) { + return errors.New("Invalid JSON in " + SchemafileName) + } + if err := writeToTar(out, filepath.Join(base, SchemafileName), c.Schema); err != nil { + return err + } + } + // Save templates for _, f := range c.Templates { n := filepath.Join(base, f.Name)