From 5a58751a053ea59b88399487a5f0f8f5c27b9461 Mon Sep 17 00:00:00 2001 From: Ryan Hockstad Date: Wed, 13 Mar 2024 18:17:00 -0400 Subject: [PATCH 1/4] merge null child chart objects Signed-off-by: Ryan Hockstad --- pkg/chartutil/coalesce.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/chartutil/coalesce.go b/pkg/chartutil/coalesce.go index f0272fd6a..40bce2a68 100644 --- a/pkg/chartutil/coalesce.go +++ b/pkg/chartutil/coalesce.go @@ -237,6 +237,9 @@ func coalesceValues(printf printFn, c *chart.Chart, v map[string]interface{}, pr printf("warning: skipped value for %s.%s: Not a table.", subPrefix, key) } } else { + // If the key is a child chart, coalesce tables with Merge set to true + merge := childChartMergeTrue(c, key, merge) + // Because v has higher precedence than nv, dest values override src // values. coalesceTablesFullKey(printf, dest, src, concatPrefix(subPrefix, key), merge) @@ -249,6 +252,15 @@ func coalesceValues(printf printFn, c *chart.Chart, v map[string]interface{}, pr } } +func childChartMergeTrue(chrt *chart.Chart, key string, merge bool) bool { + for _, subchart := range chrt.Dependencies() { + if subchart.Name() == key { + return true + } + } + return merge +} + // CoalesceTables merges a source map into a destination map. // // dest is considered authoritative. From 60fcce18d1646e266dfe8191e25a85dcdb7b0038 Mon Sep 17 00:00:00 2001 From: Scott Rigby Date: Wed, 25 Dec 2024 10:52:16 -0500 Subject: [PATCH 2/4] Tests for bugfix: Override subcharts with null values #12879 - Add consistency for null test in given values, parent chart, subchart, and sub-sub-chart - Remove bar null test to keep consistent with boat=null at top level Signed-off-by: Scott Rigby --- pkg/chartutil/coalesce_test.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/chartutil/coalesce_test.go b/pkg/chartutil/coalesce_test.go index 61b718d97..774536487 100644 --- a/pkg/chartutil/coalesce_test.go +++ b/pkg/chartutil/coalesce_test.go @@ -44,6 +44,7 @@ global: boat: true pequod: + boat: null global: name: Stinky harpooner: Tashtego @@ -55,7 +56,7 @@ pequod: boat: null nested: foo: true - bar: null + boat: null `) func withDeps(c *chart.Chart, deps ...*chart.Chart) *chart.Chart { @@ -82,6 +83,13 @@ func TestCoalesceValues(t *testing.T) { "global": map[string]interface{}{ "nested2": map[string]interface{}{"l0": "moby"}, }, + "pequod": map[string]interface{}{ + "boat": "maybe", + "ahab": map[string]interface{}{ + "boat": "maybe", + "nested": map[string]interface{}{"boat": "maybe"}, + }, + }, }, }, withDeps(&chart.Chart{ @@ -92,6 +100,11 @@ func TestCoalesceValues(t *testing.T) { "global": map[string]interface{}{ "nested2": map[string]interface{}{"l1": "pequod"}, }, + "boat": false, + "ahab": map[string]interface{}{ + "boat": false, + "nested": map[string]interface{}{"boat": false}, + }, }, }, &chart.Chart{ @@ -104,7 +117,7 @@ func TestCoalesceValues(t *testing.T) { "scope": "ahab", "name": "ahab", "boat": true, - "nested": map[string]interface{}{"foo": false, "bar": true}, + "nested": map[string]interface{}{"foo": false, "boat": true}, }, }, ), @@ -200,13 +213,18 @@ func TestCoalesceValues(t *testing.T) { t.Error("Expected nested boat key to be removed, still present") } - subchart := v["pequod"].(map[string]interface{})["ahab"].(map[string]interface{}) + subchart := v["pequod"].(map[string]interface{}) if _, ok := subchart["boat"]; ok { t.Error("Expected subchart boat key to be removed, still present") } - if _, ok := subchart["nested"].(map[string]interface{})["bar"]; ok { - t.Error("Expected subchart nested bar key to be removed, still present") + subsubchart := subchart["ahab"].(map[string]interface{}) + if _, ok := subsubchart["boat"]; ok { + t.Error("Expected sub-subchart ahab boat key to be removed, still present") + } + + if _, ok := subsubchart["nested"].(map[string]interface{})["boat"]; ok { + t.Error("Expected sub-subchart nested boat key to be removed, still present") } // CoalesceValues should not mutate the passed arguments From ef2eb552837446fe8a5a91bc68abf4d9eab685a8 Mon Sep 17 00:00:00 2001 From: Ryan Hockstad Date: Thu, 2 Jan 2025 22:19:19 -0500 Subject: [PATCH 3/4] Add test case for removing an entire object Signed-off-by: Ryan Hockstad --- pkg/chartutil/coalesce_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/chartutil/coalesce_test.go b/pkg/chartutil/coalesce_test.go index 774536487..622d99cc9 100644 --- a/pkg/chartutil/coalesce_test.go +++ b/pkg/chartutil/coalesce_test.go @@ -57,6 +57,7 @@ pequod: nested: foo: true boat: null + object: null `) func withDeps(c *chart.Chart, deps ...*chart.Chart) *chart.Chart { @@ -118,6 +119,7 @@ func TestCoalesceValues(t *testing.T) { "name": "ahab", "boat": true, "nested": map[string]interface{}{"foo": false, "boat": true}, + "object": map[string]interface{}{"foo": "bar"}, }, }, ), @@ -227,6 +229,10 @@ func TestCoalesceValues(t *testing.T) { t.Error("Expected sub-subchart nested boat key to be removed, still present") } + if _, ok := subsubchart["object"]; ok { + t.Error("Expected sub-subchart object map to be removed, still present") + } + // CoalesceValues should not mutate the passed arguments is.Equal(valsCopy, vals) } From 326c1e3f6782a7ed53980ac010c44689c0ae4fb6 Mon Sep 17 00:00:00 2001 From: Ryan Hockstad Date: Wed, 15 Jan 2025 23:29:14 -0500 Subject: [PATCH 4/4] add test for nullifying nested global value Signed-off-by: Ryan Hockstad --- pkg/chartutil/coalesce_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/chartutil/coalesce_test.go b/pkg/chartutil/coalesce_test.go index 622d99cc9..e0829b9e3 100644 --- a/pkg/chartutil/coalesce_test.go +++ b/pkg/chartutil/coalesce_test.go @@ -51,6 +51,7 @@ pequod: nested: boat: false sail: true + foo2: null ahab: scope: whale boat: null @@ -112,7 +113,7 @@ func TestCoalesceValues(t *testing.T) { Metadata: &chart.Metadata{Name: "ahab"}, Values: map[string]interface{}{ "global": map[string]interface{}{ - "nested": map[string]interface{}{"foo": "bar"}, + "nested": map[string]interface{}{"foo": "bar", "foo2": "bar2"}, "nested2": map[string]interface{}{"l2": "ahab"}, }, "scope": "ahab", @@ -170,6 +171,7 @@ func TestCoalesceValues(t *testing.T) { {"{{.pequod.ahab.nested.foo}}", "true"}, {"{{.pequod.ahab.global.name}}", "Ishmael"}, {"{{.pequod.ahab.global.nested.foo}}", "bar"}, + {"{{.pequod.ahab.global.nested.foo2}}", ""}, {"{{.pequod.ahab.global.subject}}", "Queequeg"}, {"{{.pequod.ahab.global.harpooner}}", "Tashtego"}, {"{{.pequod.global.name}}", "Ishmael"},