fix(pkg): add nil-checks

Signed-off-by: Julian Siebert <j.siebert@micromata.de>
pull/31847/head
Julian Siebert 3 months ago
parent 5bd8aa1943
commit ab717bd6d7

@ -223,11 +223,14 @@ Loop:
// win on conflicts. // win on conflicts.
if path != "" { if path != "" {
if pt, err := cvals.Table(strings.TrimSuffix(path, ".")); err == nil { if pt, err := cvals.Table(strings.TrimSuffix(path, ".")); err == nil {
if top, ok := cvals[t.Metadata.Name].(map[string]interface{}); ok { if top, ok := cvals[t.Metadata.Name].(map[string]any); ok {
if v, ok := pt[t.Metadata.Name]; ok && !istable(v) { if v, ok := pt[t.Metadata.Name]; ok && !istable(v) {
slog.Warn("skipping nested path update: value is not a table", "path", path+t.Metadata.Name) slog.Warn("skipping nested path update: value is not a table", "path", path+t.Metadata.Name)
} else { } else {
nested, _ := v.(map[string]interface{}) nested, _ := v.(map[string]any)
if nested == nil {
nested = map[string]any{}
}
pt[t.Metadata.Name] = util.CoalesceTables(nested, top) pt[t.Metadata.Name] = util.CoalesceTables(nested, top)
} }
} }

@ -228,6 +228,9 @@ Loop:
slog.Warn("skipping nested path update: value is not a table", "path", path+t.Metadata.Name) slog.Warn("skipping nested path update: value is not a table", "path", path+t.Metadata.Name)
} else { } else {
nested, _ := v.(map[string]any) nested, _ := v.(map[string]any)
if nested == nil {
nested = map[string]any{}
}
pt[t.Metadata.Name] = util.CoalesceTables(nested, top) pt[t.Metadata.Name] = util.CoalesceTables(nested, top)
} }
} }

@ -175,12 +175,12 @@ func TestDependencyEnabledAliasNestedConditionEnabled(t *testing.T) {
// User-provided values override util.enabled=true via the full alias path. // User-provided values override util.enabled=true via the full alias path.
// Expected: util IS included in the output. // Expected: util IS included in the output.
c := loadChart(t, "testdata/alias-condition-nested") c := loadChart(t, "testdata/alias-condition-nested")
vals := map[string]interface{}{ vals := map[string]any{
"midchart": map[string]interface{}{ "midchart": map[string]any{
"enabled": true, "enabled": true,
"leafchart": map[string]interface{}{ "leafchart": map[string]any{
"enabled": true, "enabled": true,
"util": map[string]interface{}{ "util": map[string]any{
"enabled": true, "enabled": true,
}, },
}, },

Loading…
Cancel
Save