diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 06aebf37b..23bb6f309 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -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 diff --git a/pkg/chart/loader/load.go b/pkg/chart/loader/load.go index 67a9f6279..ae8c89d19 100644 --- a/pkg/chart/loader/load.go +++ b/pkg/chart/loader/load.go @@ -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/"): diff --git a/pkg/chart/loader/load_test.go b/pkg/chart/loader/load_test.go index b5159d04f..855921ef4 100644 --- a/pkg/chart/loader/load_test.go +++ b/pkg/chart/loader/load_test.go @@ -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)) }