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)