Repository navigation
fix(values): erase parent-defined subchart defaults when user sets null #31976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
When a parent chart defines a value for a subchart in its own values.yaml, and the user supplies null for that key via --values, the null should erase the parent-defined default per documented Helm behavior. Previously, childChartMergeTrue correctly preserved null values through the parent coalesce pass so they could be erased during subchart-level coalescing (when the subchart itself has a default for that key). However, when the key only exists in the parent chart's values.yaml and not in the subchart's own values.yaml, no cleanup occurred — the nil persisted in the final result. Fix: after coalescing each subchart dependency, call eraseNullsWithParentDefaults to remove any remaining nil values where the parent chart defined a non-nil default. This covers the gap without disturbing keys already cleaned up at subchart level. Fixes #31919 Signed-off-by: Abhay Chaurasiya <abhaychaurasiya19@gmail.com> Signed-off-by: abhay1999 <abhaychaurasiya19@gmail.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -732,6 +732,85 @@ func TestConcatPrefix(t *testing.T) { | |
| assert.Equal(t, "a.b", concatPrefix("a", "b")) | ||
| } | ||
|
|
||
| // TestCoalesceValuesNullErasureInSubchart tests that a user-supplied null value | ||
| // erases a key defined in the parent chart's values.yaml for a subchart, | ||
| // even when that key has no default in the subchart's own values.yaml. | ||
| // Regression test for https://github.com/helm/helm/issues/31919 | ||
| func TestCoalesceValuesNullErasureInSubchart(t *testing.T) { | ||
| is := assert.New(t) | ||
|
|
||
| // Parent chart defines "key" for subchart in its own values.yaml. | ||
| // The subchart itself does NOT define "key" in its values.yaml. | ||
| subchart := &chart.Chart{ | ||
| Metadata: &chart.Metadata{Name: "mysubchart"}, | ||
| Values: map[string]any{ | ||
| "other": "subchart_default", | ||
| }, | ||
| } | ||
| parent := withDeps(&chart.Chart{ | ||
| Metadata: &chart.Metadata{Name: "parent"}, | ||
| Values: map[string]any{ | ||
| "mysubchart": map[string]any{ | ||
| "key": "parent_defined_value", | ||
| }, | ||
| }, | ||
| }, subchart) | ||
|
|
||
| // User passes null for mysubchart.key to erase the parent-defined default. | ||
| vals := map[string]any{ | ||
| "mysubchart": map[string]any{ | ||
| "key": nil, | ||
| }, | ||
| } | ||
|
|
||
| v, err := CoalesceValues(parent, vals) | ||
| is.NoError(err) | ||
|
|
||
| sub, ok := v["mysubchart"].(map[string]any) | ||
| is.True(ok, "mysubchart is not a map") | ||
|
|
||
| // "other" should still be present (subchart default) | ||
| is.Equal("subchart_default", sub["other"]) | ||
|
|
||
| // "key" should be removed — user explicitly set it to null to erase the parent default | ||
| _, present := sub["key"] | ||
| is.False(present, "Expected mysubchart.key to be erased by user null, but it is still present") | ||
| } | ||
|
|
||
| // TestCoalesceValuesNullErasurePreservesUserValues ensures that when a parent chart | ||
| // defines a null for a subchart key, the user's non-nil value is still preserved. | ||
| func TestCoalesceValuesNullErasurePreservesUserValues(t *testing.T) { | ||
| is := assert.New(t) | ||
|
|
||
| subchart := &chart.Chart{ | ||
| Metadata: &chart.Metadata{Name: "mysubchart"}, | ||
| Values: map[string]any{}, | ||
| } | ||
| parent := withDeps(&chart.Chart{ | ||
| Metadata: &chart.Metadata{Name: "parent"}, | ||
| Values: map[string]any{ | ||
| "mysubchart": map[string]any{ | ||
| "key": nil, // parent chart defaults this to null | ||
| }, | ||
| }, | ||
| }, subchart) | ||
|
|
||
| // User provides a real value — should not be erased by the parent's null default | ||
| vals := map[string]any{ | ||
| "mysubchart": map[string]any{ | ||
| "key": "user_value", | ||
| }, | ||
| } | ||
|
|
||
| v, err := CoalesceValues(parent, vals) | ||
| is.NoError(err) | ||
|
|
||
| sub, ok := v["mysubchart"].(map[string]any) | ||
| is.True(ok, "mysubchart is not a map") | ||
|
|
||
| is.Equal("user_value", sub["key"], "user value should not be overwritten by parent null default") | ||
| } | ||
|
Comment on lines
+805
to
+809
|
||
|
|
||
| // TestCoalesceValuesEmptyMapWithNils tests the full CoalesceValues scenario | ||
| // from issue #31643 where chart has data: {} and user provides data: {foo: bar, baz: ~} | ||
| func TestCoalesceValuesEmptyMapWithNils(t *testing.T) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests use
assert.True(ok, ...)after a type assertion and then immediately index into the map (sub["other"],sub["key"]). If the assertion fails,assertdoes not stop the test, so this will panic and obscure the actual failure. Prefer a fatal check (e.g.,require.True/require.IsType, orif !ok { t.Fatalf(...); return }) before usingsub.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed in the follow-up commit — switched to
require.True/require.NoErrorso the test fails fast instead of panicking on the map indexing.