fix(pkg/chartutil): include values.schema.json in packaged chart

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 <alling.simon@gmail.com>

Co-authored-by: Andreas Lindhé <andreas@lindhe.io>
pull/6519/head
Simon Alling 5 years ago
parent 0141f9c806
commit 50675e7cd7

@ -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.

@ -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)

Loading…
Cancel
Save