Commit 51b59497 authored by Sam Leavens's avatar Sam Leavens

ref(pkg/chartutil): decrease map lookups

Decrease map lookups in `chartutil.coalesceValues` and move comment to unit
test.

Closes #2663
parent 3cf8f2c8
...@@ -278,17 +278,10 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf ...@@ -278,17 +278,10 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf
} }
for key, val := range nv { for key, val := range nv {
if _, ok := v[key]; !ok { if value, ok := v[key]; ok {
// If the key is not in v, copy it from nv. if value == nil {
v[key] = val
} else if ok && v[key] == nil {
// When the YAML value is null, we remove the value's key.
// This allows Helm's various sources of values (value files or --set) to
// remove incompatible keys from any previous chart, file, or set values.
// ref: http://www.yaml.org/spec/1.2/spec.html#id2803362
delete(v, key) delete(v, key)
continue } else if dest, ok := value.(map[string]interface{}); ok {
} else if dest, ok := v[key].(map[string]interface{}); ok {
// if v[key] is a table, merge nv's val table into v[key]. // if v[key] is a table, merge nv's val table into v[key].
src, ok := val.(map[string]interface{}) src, ok := val.(map[string]interface{})
if !ok { if !ok {
...@@ -299,6 +292,10 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf ...@@ -299,6 +292,10 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf
// values. // values.
coalesceTables(dest, src) coalesceTables(dest, src)
} }
} else {
// If the key is not in v, copy it from nv.
v[key] = val
}
} }
return v, nil return v, nil
} }
......
...@@ -350,6 +350,10 @@ func TestCoalesceValues(t *testing.T) { ...@@ -350,6 +350,10 @@ func TestCoalesceValues(t *testing.T) {
} }
} }
// When the YAML value is null, we remove the value's key.
// This allows Helm's various sources of values (value files or --set) to
// remove incompatible keys from any previous chart, file, or set values.
// ref: http://www.yaml.org/spec/1.2/spec.html#id2803362
nullKeys := []string{"bottom", "right", "left", "front"} nullKeys := []string{"bottom", "right", "left", "front"}
for _, nullKey := range nullKeys { for _, nullKey := range nullKeys {
if _, ok := v[nullKey]; ok { if _, ok := v[nullKey]; ok {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment