Added export-values handling to dependencies

Signed-off-by: Withnale <withnale@users.github.com>
pull/7477/head
Withnale 6 years ago
parent 8ea6b970ec
commit 1bc87d8203

@ -45,6 +45,7 @@ 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 []interface{} `json:"export-values,omitempty"`
// Alias usable alias to be used for the chart
Alias string `json:"alias,omitempty"`
}

@ -227,9 +227,44 @@ func processImportValues(c *chart.Chart) error {
return err
}
b := make(map[string]interface{})
// import values from each dependency if specified in import-values
for _, r := range c.Metadata.Dependencies {
var outiv []interface{}
// export values to each dependency if specified in export-values
for _, riv := range r.ExportValues {
iv := riv.(map[string]interface{})
child := iv["child"].(string)
parent := iv["parent"].(string)
outiv = append(outiv, map[string]string{
"child": child,
"parent": parent,
})
name := r.Name
if r.Alias != "" {
name = r.Alias
}
// get parent table
vv, err := cvals.Table(parent)
if err != nil {
// parent is not a table - need to check if it's a value
value, err := cvals.PathValue(parent)
if err != nil {
log.Printf("Warning: Path does not exist: %v", err)
continue
}
var childPath = name + "." + child
var lastDot = strings.LastIndex(childPath, ".")
base := map[string]interface{}{
childPath[lastDot+1:]: value,
}
b = CoalesceTables(cvals, pathToMap(childPath[0:lastDot], base))
} else {
// create value map from parent to be merged into child
b = CoalesceTables(cvals, pathToMap(name+"."+child, vv.AsMap()))
}
}
// import values from each dependency if specified in import-values
for _, riv := range r.ImportValues {
switch iv := riv.(type) {
case map[string]interface{}:

@ -212,6 +212,10 @@ func TestProcessDependencyImportValues(t *testing.T) {
e["SCBexported2A"] = "blaster"
e["global.SC1exported2.all.SC1exported3"] = "SC1expstr"
// `imports` style
e["subchart1.mytags.back-end"] = "false"
e["subchart1.mytags.front-end"] = "true"
if err := processDependencyImportValues(c); err != nil {
t.Fatalf("processing import values dependencies %v", err)
}

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

Loading…
Cancel
Save