Fix codefences and nits in charts.md. Correct whitespace in charts. Add clarity to description of ImportValues requirements field.

pull/2112/head
Justin Scott 9 years ago
parent 1a8e728ed9
commit 3bf143f052

@ -306,44 +306,44 @@ helm install --set tags.front-end=true --set subchart2.enabled=false
In some cases it is desirable to allow a child chart's values to propagate to the parent chart and be In some cases it is desirable to allow a child chart's values to propagate to the parent chart and be
shared as common defaults. An additional benefit of using the `exports` format is that it will enable future shared as common defaults. An additional benefit of using the `exports` format is that it will enable future
tooling to introspect user settable values. tooling to introspect user-settable values.
The keys containing the values to be imported can be specified in the parent chart's requirements.yaml using The keys containing the values to be imported can be specified in the parent chart's `requirements.yaml` file
a YAML list. Each item in the list is a key which is imported from the child chart's `exports` field. using a YAML list. Each item in the list is a key which is imported from the child chart's `exports` field.
To import values not contained in the `exports` key, use the [child/parent](#using-the-child/parent-format) format. To import values not contained in the `exports` key, use the [child/parent](#using-the-child/parent-format) format.
Examples of both formats are described below.
##### Using the exports format ##### Using the exports format
If a child chart's values.yaml contains an `exports` field at the root, it's contents may be imported If a child chart's `values.yaml` file contains an `exports` field at the root, its contents may be imported
directly into the parent's values by specifying the keys to import as in the example below: directly into the parent's values by specifying the keys to import as in the example below:
```` ```yaml
# parent's requirements.yaml # parent's requirements.yaml file
... ...
import-values: import-values:
- data - data
```` ```
```` ```yaml
# child's values.yaml # child's values.yaml file
... ...
exports: exports:
data: data:
myint: 99 myint: 99
```` ```
Since we are specifying the key `data` in our import list, Helm looks in the the `exports` field of the child Since we are specifying the key `data` in our import list, Helm looks in the the `exports` field of the child
chart for `data` key and imports its contents. chart for `data` key and imports its contents.
The final parent values would contain our exported field: The final parent values would contain our exported field:
```` ```yaml
# parent's values # parent's values file
... ...
myint: 99 myint: 99
```` ```
Please note the parent key `data` is not contained in the parent's final values. If you need to specify the Please note the parent key `data` is not contained in the parent's final values. If you need to specify the
parent key, use the 'child/parent' format. parent key, use the 'child/parent' format.
@ -357,8 +357,8 @@ values (`parent`).
The `import-values` in the example below instructs Helm to take any values found at `child:` path and copy them The `import-values` in the example below instructs Helm to take any values found at `child:` path and copy them
to the parent's values at the path specified in `parent:` to the parent's values at the path specified in `parent:`
```` ```yaml
# parent's requirements.yaml # parent's requirements.yaml file
dependencies: dependencies:
- name: subchart1 - name: subchart1
repository: http://localhost:10191 repository: http://localhost:10191
@ -367,32 +367,31 @@ dependencies:
import-values: import-values:
- child: default.data - child: default.data
parent: myimports parent: myimports
```` ```
In the above example, values found at `default.data` in the subchart1's values will be imported In the above example, values found at `default.data` in the subchart1's values will be imported
to the `myimports` key in the parent chart's values as detailed below: to the `myimports` key in the parent chart's values as detailed below:
```` ```yaml
# parent's values # parent's values.yaml file
myimports: myimports:
myint: 0 myint: 0
mybool: false mybool: false
mystring: "helm rocks!" mystring: "helm rocks!"
```
```` ```yaml
```` # subchart1's values.yaml file
# subchart1's values.yaml
default: default:
data: data:
myint: 999 myint: 999
mybool: true mybool: true
```` ```
The parent chart's resulting values would be: The parent chart's resulting values would be:
```` ```yaml
# parent's final values # parent's final values
myimports: myimports:
@ -400,7 +399,7 @@ myimports:
mybool: true mybool: true
mystring: "helm rocks!" mystring: "helm rocks!"
```` ```
The parent's final values now contains the `myint` and `mybool` fields imported from subchart1. The parent's final values now contains the `myint` and `mybool` fields imported from subchart1.

@ -62,7 +62,8 @@ type Dependency struct {
Tags []string `json:"tags"` Tags []string `json:"tags"`
// Enabled bool determines if chart should be loaded // Enabled bool determines if chart should be loaded
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
// ImportValues holds the mapping of source values to parent key to be imported // 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"` ImportValues []interface{} `json:"import-values"`
} }
@ -315,7 +316,7 @@ func getParents(c *chart.Chart, out []*chart.Chart) []*chart.Chart {
return out return out
} }
// processImportValues merges values from child to parent based on ImportValues field. // processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field.
func processImportValues(c *chart.Chart, v *chart.Config) error { func processImportValues(c *chart.Chart, v *chart.Config) error {
reqs, err := LoadRequirements(c) reqs, err := LoadRequirements(c)
if err != nil { if err != nil {
@ -327,7 +328,7 @@ func processImportValues(c *chart.Chart, v *chart.Config) error {
return err return err
} }
nv := v.GetValues() nv := v.GetValues()
b := make(map[string]interface{}) b := make(map[string]interface{}, len(nv))
// convert values to map // convert values to map
for kk, vvv := range nv { for kk, vvv := range nv {
b[kk] = vvv b[kk] = vvv
@ -348,21 +349,25 @@ func processImportValues(c *chart.Chart, v *chart.Config) error {
// get child table // get child table
vv, err := cvals.Table(s) vv, err := cvals.Table(s)
if err != nil { if err != nil {
log.Printf("Warning: ImportValues missing table %v", err) log.Printf("Warning: ImportValues missing table: %v", err)
continue continue
} }
// create value map from child to be merged into parent // create value map from child to be merged into parent
vm := pathToMap(nm["parent"], vv.AsMap()) vm := pathToMap(nm["parent"], vv.AsMap())
b = coalesceTables(cvals, vm) b = coalesceTables(cvals, vm)
case string: case string:
nm := make(map[string]string) nm := map[string]string{
"child": "exports." + iv,
"parent": ".",
}
/*nm := make(map[string]string)
nm["child"] = "exports." + iv nm["child"] = "exports." + iv
nm["parent"] = "." nm["parent"] = "."*/
outiv = append(outiv, nm) outiv = append(outiv, nm)
s := r.Name + "." + nm["child"] s := r.Name + "." + nm["child"]
vm, err := cvals.Table(s) vm, err := cvals.Table(s)
if err != nil { if err != nil {
log.Printf("Warning: ImportValues missing table %v", err) log.Printf("Warning: ImportValues missing table: %v", err)
continue continue
} }
b = coalesceTables(b, vm.AsMap()) b = coalesceTables(b, vm.AsMap())

@ -30,8 +30,6 @@ global:
metadata: metadata:
all: all:
port: 8775 port: 8775
test:
dummy: 1

Loading…
Cancel
Save