pull/32195/merge
Rayan Salhab 1 day ago committed by GitHub
commit 89a69dca0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -266,11 +266,13 @@ func coalesceValues(printf printFn, c chart.Charter, v map[string]any, prefix st
// If the key is not in v, copy it from nv. // If the key is not in v, copy it from nv.
// When coalescing, skip chart default nils and clean nils from // When coalescing, skip chart default nils and clean nils from
// nested maps so they don't shadow globals or produce %!s(<nil>). // nested maps so they don't shadow globals or produce %!s(<nil>).
// But when the key targets a child chart, nils in the parent's
// values are intentional overrides for the child chart defaults.
if !merge { if !merge {
if val == nil { if val == nil {
continue continue
} }
if sub, ok := val.(map[string]any); ok { if sub, ok := val.(map[string]any); ok && !childChartMergeTrue(c, key, merge) {
cleanNilValues(sub) cleanNilValues(sub)
} }
} }

@ -825,3 +825,49 @@ func TestCoalesceValuesSubchartNilCleanedWhenUserPartiallyOverrides(t *testing.T
_, ok = keyMapping["password"] _, ok = keyMapping["password"]
is.False(ok, "Expected keyMapping.password (nil from chart defaults) to be removed even when user partially overrides the map") is.False(ok, "Expected keyMapping.password (nil from chart defaults) to be removed even when user partially overrides the map")
} }
// TestCoalesceValuesParentSubchartNullOverrideWithoutUserValues tests that a
// null in a parent's values.yaml under a subchart scope erases the subchart's
// default even when no user-provided values target that subchart.
// Regression test for issue #32132.
func TestCoalesceValuesParentSubchartNullOverrideWithoutUserValues(t *testing.T) {
is := assert.New(t)
subchart := &chart.Chart{
Metadata: &chart.Metadata{Name: "child"},
Values: map[string]any{
"securityContext": map[string]any{
"runAsGroup": 65534,
"runAsNonRoot": true,
"runAsUser": 65534,
},
},
}
parent := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "parent"},
Values: map[string]any{
"child": map[string]any{
"securityContext": map[string]any{
"runAsGroup": nil,
"runAsUser": nil,
},
},
},
}, subchart)
v, err := CoalesceValues(parent, map[string]any{})
is.NoError(err)
childVals, ok := v["child"].(map[string]any)
is.True(ok, "child values should be a map")
securityContext, ok := childVals["securityContext"].(map[string]any)
is.True(ok, "securityContext should be a map")
_, ok = securityContext["runAsGroup"]
is.False(ok, "Expected parent null override to erase subchart runAsGroup default")
_, ok = securityContext["runAsUser"]
is.False(ok, "Expected parent null override to erase subchart runAsUser default")
is.Equal(true, securityContext["runAsNonRoot"], "Subchart default not nulled by the parent should be preserved")
}

Loading…
Cancel
Save