Added support for export-values in requirements

pull/3243/head
Withnale 8 years ago
parent 782f855ad9
commit 89f64183cb

@ -186,6 +186,10 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
err = chartutil.ProcessRequirementsExportValues(c)
if err != nil {
return err
}
// Set up engine.
renderer := engine.New()

@ -66,6 +66,9 @@ type Dependency struct {
// ImportValues holds the mapping of source values to parent key to be imported. Each item can be a
// string or pair of child/parent sublist items.
ImportValues []interface{} `json:"import-values,omitempty"`
// ExportValues holds the mapping of source values to parent key to be exported. Each item can be a
// string or pair of child/parent sublist items.
ExportValues []interface{} `json:"export-values,omitempty"`
// Alias usable alias to be used for the chart
Alias string `json:"alias,omitempty"`
}
@ -445,6 +448,60 @@ func processImportValues(c *chart.Chart) error {
return nil
}
// processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field.
func processExportValues(c *chart.Chart) error {
reqs, err := LoadRequirements(c)
if err != nil {
return err
}
// combine chart values and empty config to get Values
cvals, err := CoalesceValues(c, &chart.Config{})
if err != nil {
return err
}
b := make(map[string]interface{}, 0)
// import values from each dependency if specified in import-values
for _, r := range reqs.Dependencies {
if len(r.ExportValues) > 0 {
var outiv []interface{}
for _, riv := range r.ExportValues {
iv := riv.(map[string]interface{})
nm := map[string]string{
"child": iv["child"].(string),
"parent": iv["parent"].(string),
}
outiv = append(outiv, nm)
s := nm["parent"]
// get child table
vv, err := cvals.Table(s)
if err != nil {
log.Printf("Warning: ExportValues missing table: %v", err)
continue
}
name := r.Name
if r.Alias != "" {
name = r.Alias
}
// create value map from child to be merged into parent
vm := pathToMap(name+"."+nm["child"], vv.AsMap())
b = coalesceTables(cvals, vm)
}
// set our formatted import values
r.ExportValues = outiv
}
}
b = coalesceTables(b, cvals)
y, err := yaml.Marshal(b)
if err != nil {
return err
}
// set the new values
c.Values = &chart.Config{Raw: string(y)}
return nil
}
// ProcessRequirementsImportValues imports specified chart values from child to parent.
func ProcessRequirementsImportValues(c *chart.Chart) error {
pc := getParents(c, nil)
@ -454,3 +511,13 @@ func ProcessRequirementsImportValues(c *chart.Chart) error {
return nil
}
// ProcessRequirementsExportValues exports specified chart values from parent to child.
func ProcessRequirementsExportValues(c *chart.Chart) error {
pc := getParents(c, nil)
for i := len(pc) - 1; i >= 0; i-- {
processExportValues(pc[i])
}
return nil
}

@ -279,6 +279,10 @@ func TestProcessRequirementsImportValues(t *testing.T) {
e["SCBexported2A"] = "blaster"
e["global.SC1exported2.all.SC1exported3"] = "SC1expstr"
// `imports`
e["subchart1.mytags.back-end"] = "false"
e["subchart1.mytags.front-end"] = "true"
verifyRequirementsImportValues(t, c, v, e)
}
func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Config, e map[string]string) {
@ -287,6 +291,10 @@ func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Confi
if err != nil {
t.Errorf("Error processing import values requirements %v", err)
}
err = ProcessRequirementsExportValues(c)
if err != nil {
t.Errorf("Error processing import values requirements %v", err)
}
cv := c.GetValues()
cc, err := ReadValues([]byte(cv.Raw))
if err != nil {

@ -21,6 +21,9 @@ dependencies:
parent: .
- SCBexported2
- SC1exported1
export-values:
- child: mytags
parent: tags
- name: subchart2
repository: http://localhost:10191

Loading…
Cancel
Save