Add Schema to Chart and loader

Signed-off-by: Ian Howell <ian.howell0@gmail.com>
pull/5350/head
Ian Howell 7 years ago
parent 8e6433a53f
commit 1ad4a26a96

@ -31,6 +31,8 @@ type Chart struct {
RawValues []byte
// Values are default config for this template.
Values map[string]interface{}
// Schema is an optional JSON schema for imposing structure on Values
Schema map[string]interface{}
// Files are miscellaneous files in a chart archive,
// e.g. README, LICENSE, etc.
Files []*File

@ -90,6 +90,11 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
return c, errors.Wrap(err, "cannot load values.yaml")
}
c.RawValues = f.Data
case f.Name == "values.schema.yaml":
c.Schema = make(map[string]interface{})
if err := yaml.Unmarshal(f.Data, &c.Schema); err != nil {
return c, errors.Wrap(err, "cannot load values.schema.yaml")
}
case strings.HasPrefix(f.Name, "templates/"):
c.Templates = append(c.Templates, &chart.File{Name: f.Name, Data: f.Data})
case strings.HasPrefix(f.Name, "charts/"):

@ -78,6 +78,10 @@ icon: https://example.com/64x64.png
Name: "values.yaml",
Data: []byte("var: some values"),
},
{
Name: "values.schema.yaml",
Data: []byte("type: Values"),
},
{
Name: "templates/deployment.yaml",
Data: []byte("some deployment"),
@ -101,6 +105,10 @@ icon: https://example.com/64x64.png
t.Error("Expected chart values to be populated with default values")
}
if c.Schema["type"] != "Values" {
t.Error("Expected chart schema to be populated with default values")
}
if len(c.Templates) != 2 {
t.Errorf("Expected number of templates == 2, got %d", len(c.Templates))
}

Loading…
Cancel
Save