feat: handling error in coalesce

Signed-off-by: antyagi <anubhav.tyagi@soprabanking.com>
pull/31841/head
antyagi 7 months ago
parent d5bfb706b3
commit 05ab813745

@ -121,7 +121,10 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi
dvmap := dv.(map[string]any) dvmap := dv.(map[string]any)
subPrefix := concatPrefix(prefix, ch.Name()) subPrefix := concatPrefix(prefix, ch.Name())
// Get globals out of dest and merge them into dvmap. // Get globals out of dest and merge them into dvmap.
coalesceGlobals(printf, dvmap, dest, subPrefix, merge) err = coalesceGlobals(printf, dvmap, dest, subPrefix, merge)
if err != nil {
return dest, err
}
// Now coalesce the rest of the values. // Now coalesce the rest of the values.
var err error var err error
dest[sub.Name()], err = coalesce(printf, subchart, dvmap, subPrefix, merge) dest[sub.Name()], err = coalesce(printf, subchart, dvmap, subPrefix, merge)
@ -136,21 +139,21 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi
// coalesceGlobals copies the globals out of src and merges them into dest. // coalesceGlobals copies the globals out of src and merges them into dest.
// //
// For convenience, returns dest. // For convenience, returns dest.
func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) { func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) error {
var dg, sg map[string]any var dg, sg map[string]any
if destglob, ok := dest[common.GlobalKey]; !ok { if destglob, ok := dest[common.GlobalKey]; !ok {
dg = make(map[string]any) dg = make(map[string]any)
} else if dg, ok = destglob.(map[string]any); !ok { } else if dg, ok = destglob.(map[string]any); !ok {
printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey) printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey)
return return nil
} }
if srcglob, ok := src[common.GlobalKey]; !ok { if srcglob, ok := src[common.GlobalKey]; !ok {
sg = make(map[string]any) sg = make(map[string]any)
} else if sg, ok = srcglob.(map[string]any); !ok { } else if sg, ok = srcglob.(map[string]any); !ok {
printf("warning: skipping globals because source %s is not a table.", common.GlobalKey) printf("warning: skipping globals because source %s is not a table.", common.GlobalKey)
return return nil
} }
// EXPERIMENTAL: In the past, we have disallowed globals to test tables. This // EXPERIMENTAL: In the past, we have disallowed globals to test tables. This
@ -159,8 +162,15 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _
// tables in globals. // tables in globals.
for key, val := range sg { for key, val := range sg {
if istable(val) { if istable(val) {
valCopy, _ := copystructure.Copy(val) valCopy, err := copystructure.Copy(val)
vv := valCopy.(map[string]interface{}) if err != nil {
return err
}
vv, ok := valCopy.(map[string]any)
if !ok {
printf("warning: unable to convert globals copy to Helm values type")
continue
}
if destv, ok := dg[key]; !ok { if destv, ok := dg[key]; !ok {
// Here there is no merge. We're just adding. // Here there is no merge. We're just adding.
dg[key] = vv dg[key] = vv
@ -187,6 +197,7 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _
} }
} }
dest[common.GlobalKey] = dg dest[common.GlobalKey] = dg
return nil
} }

Loading…
Cancel
Save