Merge pull request #9333 from bgutjahr/fix-9332

Fix 9332
pull/9707/head
Martin Hickey 3 years ago committed by GitHub
commit c3ad0c7242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -120,13 +120,11 @@ func coalesceGlobals(dest, src map[string]interface{}) {
// top-down. // top-down.
CoalesceTables(vv, destvmap) CoalesceTables(vv, destvmap)
dg[key] = vv dg[key] = vv
continue
} }
} }
} else if dv, ok := dg[key]; ok && istable(dv) { } else if dv, ok := dg[key]; ok && istable(dv) {
// It's not clear if this condition can actually ever trigger. // It's not clear if this condition can actually ever trigger.
log.Printf("key %s is table. Skipping", key) log.Printf("key %s is table. Skipping", key)
continue
} else { } else {
// TODO: Do we need to do any additional checking on the value? // TODO: Do we need to do any additional checking on the value?
dg[key] = val dg[key] = val
@ -159,15 +157,15 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) {
src, ok := val.(map[string]interface{}) src, ok := val.(map[string]interface{})
if !ok { if !ok {
// If the original value is nil, there is nothing to coalesce, so we don't print // If the original value is nil, there is nothing to coalesce, so we don't print
// the warning but simply continue // the warning
if val != nil { if val != nil {
log.Printf("warning: skipped value for %s: Not a table.", key) log.Printf("warning: skipped value for %s: Not a table.", key)
} }
continue } else {
// Because v has higher precedence than nv, dest values override src
// values.
CoalesceTables(dest, src)
} }
// Because v has higher precedence than nv, dest values override src
// values.
CoalesceTables(dest, src)
} }
} else { } else {
// If the key is not in v, copy it from nv. // If the key is not in v, copy it from nv.

@ -78,17 +78,27 @@ func TestCoalesceValues(t *testing.T) {
"right": "exists", "right": "exists",
"scope": "moby", "scope": "moby",
"top": "nope", "top": "nope",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l0": "moby"},
},
}, },
}, },
withDeps(&chart.Chart{ withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "pequod"}, Metadata: &chart.Metadata{Name: "pequod"},
Values: map[string]interface{}{"name": "pequod", "scope": "pequod"}, Values: map[string]interface{}{
"name": "pequod",
"scope": "pequod",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l1": "pequod"},
},
},
}, },
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "ahab"}, Metadata: &chart.Metadata{Name: "ahab"},
Values: map[string]interface{}{ Values: map[string]interface{}{
"global": map[string]interface{}{ "global": map[string]interface{}{
"nested": map[string]interface{}{"foo": "bar"}, "nested": map[string]interface{}{"foo": "bar"},
"nested2": map[string]interface{}{"l2": "ahab"},
}, },
"scope": "ahab", "scope": "ahab",
"name": "ahab", "name": "ahab",
@ -99,7 +109,12 @@ func TestCoalesceValues(t *testing.T) {
), ),
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "spouter"}, Metadata: &chart.Metadata{Name: "spouter"},
Values: map[string]interface{}{"scope": "spouter"}, Values: map[string]interface{}{
"scope": "spouter",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l1": "spouter"},
},
},
}, },
) )
@ -152,6 +167,19 @@ func TestCoalesceValues(t *testing.T) {
{"{{.spouter.global.nested.boat}}", "true"}, {"{{.spouter.global.nested.boat}}", "true"},
{"{{.pequod.global.nested.sail}}", "true"}, {"{{.pequod.global.nested.sail}}", "true"},
{"{{.spouter.global.nested.sail}}", "<no value>"}, {"{{.spouter.global.nested.sail}}", "<no value>"},
{"{{.global.nested2.l0}}", "moby"},
{"{{.global.nested2.l1}}", "<no value>"},
{"{{.global.nested2.l2}}", "<no value>"},
{"{{.pequod.global.nested2.l0}}", "moby"},
{"{{.pequod.global.nested2.l1}}", "pequod"},
{"{{.pequod.global.nested2.l2}}", "<no value>"},
{"{{.pequod.ahab.global.nested2.l0}}", "moby"},
{"{{.pequod.ahab.global.nested2.l1}}", "pequod"},
{"{{.pequod.ahab.global.nested2.l2}}", "ahab"},
{"{{.spouter.global.nested2.l0}}", "moby"},
{"{{.spouter.global.nested2.l1}}", "spouter"},
{"{{.spouter.global.nested2.l2}}", "<no value>"},
} }
for _, tt := range tests { for _, tt := range tests {

Loading…
Cancel
Save