pull/32531/merge
water 1 day ago committed by GitHub
commit e56084706b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -251,9 +251,11 @@ func coalesceValues(printf printFn, c chart.Charter, v map[string]any, prefix st
// If the key is a child chart, coalesce tables with Merge set to true
merge := childChartMergeTrue(c, key, merge)
// When coalescing, clean nils from chart defaults before merging
// so they don't leak into the result.
if !merge {
// When coalescing a subchart default, clean nils from the chart
// defaults before merging so they don't leak into the result.
// Null values defined directly in the top-level chart's own
// values.yaml are preserved (see helm#32530).
if !merge && prefix != "" {
cleanNilValues(src)
}
@ -264,9 +266,11 @@ func coalesceValues(printf printFn, c chart.Charter, v map[string]any, prefix st
}
} else {
// If the key is not in v, copy it from nv.
// When coalescing, skip chart default nils and clean nils from
// nested maps so they don't shadow globals or produce %!s(<nil>).
if !merge {
// When coalescing a subchart default, skip chart default nils and
// clean nils from nested maps so they don't shadow globals or
// produce %!s(<nil>). Null values defined directly in the top-level
// chart's own values.yaml are preserved (see helm#32530).
if !merge && prefix != "" {
if val == nil {
continue
}

@ -825,3 +825,36 @@ func TestCoalesceValuesSubchartNilCleanedWhenUserPartiallyOverrides(t *testing.T
_, ok = keyMapping["password"]
is.False(ok, "Expected keyMapping.password (nil from chart defaults) to be removed even when user partially overrides the map")
}
// TestCoalesceValuesTopLevelNullsPreserved tests that null values defined directly in
// the top-level chart's own values.yaml are preserved in the coalesced result.
// Regression test for issue #32530.
func TestCoalesceValuesTopLevelNullsPreserved(t *testing.T) {
is := assert.New(t)
req := require.New(t)
c := &chart.Chart{
Metadata: &chart.Metadata{Name: "test"},
Values: map[string]any{
"stuff": map[string]any{
"foo": "bar",
"baz": nil,
},
"foobar": nil,
},
}
v, err := CoalesceValues(c, map[string]any{})
req.NoError(err)
// The top-level null key should be preserved.
is.Contains(v, "foobar", "Expected top-level null key foobar to be preserved")
is.Nil(v["foobar"], "Expected foobar to be nil")
// The nested null key should be preserved.
stuff, ok := v["stuff"].(map[string]any)
is.True(ok, "stuff should be a map")
is.Contains(stuff, "baz", "Expected nested null key stuff.baz to be preserved")
is.Nil(stuff["baz"], "Expected stuff.baz to be nil")
is.Equal("bar", stuff["foo"], "Expected stuff.foo to be preserved")
}

Loading…
Cancel
Save