diff --git a/pkg/chart/dependency.go b/pkg/chart/dependency.go index 9ec4544c2..5d25f71ec 100644 --- a/pkg/chart/dependency.go +++ b/pkg/chart/dependency.go @@ -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"` } diff --git a/pkg/chartutil/dependencies.go b/pkg/chartutil/dependencies.go index d2e7d6dc9..7918d4c9c 100644 --- a/pkg/chartutil/dependencies.go +++ b/pkg/chartutil/dependencies.go @@ -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{}: diff --git a/pkg/chartutil/dependencies_test.go b/pkg/chartutil/dependencies_test.go index 342d7fe87..a62ca80dd 100644 --- a/pkg/chartutil/dependencies_test.go +++ b/pkg/chartutil/dependencies_test.go @@ -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) } diff --git a/pkg/chartutil/testdata/subpop/Chart.yaml b/pkg/chartutil/testdata/subpop/Chart.yaml index 27118672a..9c34f3772 100644 --- a/pkg/chartutil/testdata/subpop/Chart.yaml +++ b/pkg/chartutil/testdata/subpop/Chart.yaml @@ -25,6 +25,9 @@ dependencies: parent: . - SCBexported2 - SC1exported1 + export-values: + - child: mytags + parent: tags - name: subchart2 repository: http://localhost:10191