@ -203,7 +203,7 @@ func coalesceDeps(chrt *chart.Chart, dest map[string]interface{}) (map[string]in
dvmap := dv . ( map [ string ] interface { } )
dvmap := dv . ( map [ string ] interface { } )
// Get globals out of dest and merge them into dvmap.
// Get globals out of dest and merge them into dvmap.
coalesceGlobals ( dvmap , dest )
coalesceGlobals ( dvmap , dest , chrt . Metadata . Name )
var err error
var err error
// Now coalesce the rest of the values.
// Now coalesce the rest of the values.
@ -219,20 +219,20 @@ func coalesceDeps(chrt *chart.Chart, dest map[string]interface{}) (map[string]in
// 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 ( dest , src map [ string ] interface { } ) map [ string ] interface { } {
func coalesceGlobals ( dest , src map [ string ] interface { } , chartName string ) map [ string ] interface { } {
var dg , sg map [ string ] interface { }
var dg , sg map [ string ] interface { }
if destglob , ok := dest [ GlobalKey ] ; ! ok {
if destglob , ok := dest [ GlobalKey ] ; ! ok {
dg = map [ string ] interface { } { }
dg = map [ string ] interface { } { }
} else if dg , ok = destglob . ( map [ string ] interface { } ) ; ! ok {
} else if dg , ok = destglob . ( map [ string ] interface { } ) ; ! ok {
log . Printf ( " warning: skipping globals because destination %s is not a table." , GlobalKey )
log . Printf ( " Warning: Skipping globals for chart '%s' because destination '%s' is not a table.", chartName , GlobalKey )
return dg
return dg
}
}
if srcglob , ok := src [ GlobalKey ] ; ! ok {
if srcglob , ok := src [ GlobalKey ] ; ! ok {
sg = map [ string ] interface { } { }
sg = map [ string ] interface { } { }
} else if sg , ok = srcglob . ( map [ string ] interface { } ) ; ! ok {
} else if sg , ok = srcglob . ( map [ string ] interface { } ) ; ! ok {
log . Printf ( " warning: skipping globals because source %s is not a table." , GlobalKey )
log . Printf ( " Warning: skipping globals for chart '%s' because source '%s' is not a table.", chartName , GlobalKey )
return dg
return dg
}
}
@ -247,11 +247,11 @@ func coalesceGlobals(dest, src map[string]interface{}) map[string]interface{} {
if destvmap , ok := destv . ( map [ string ] interface { } ) ; ok {
if destvmap , ok := destv . ( map [ string ] interface { } ) ; ok {
// Basically, we reverse order of coalesce here to merge
// Basically, we reverse order of coalesce here to merge
// top-down.
// top-down.
coalesceTables ( vv , destvmap )
coalesceTables ( vv , destvmap , chartName )
dg [ key ] = vv
dg [ key ] = vv
continue
continue
} else {
} else {
log . Printf ( " Conflict: cannot merge map onto non-map for %q. Skipping." , key )
log . Printf ( " Warning: For chart '%s', cannot merge map onto non-map for key '%q'. Skipping.", chartName , key )
}
}
} else {
} else {
// Here there is no merge. We're just adding.
// Here there is no merge. We're just adding.
@ -259,7 +259,7 @@ func coalesceGlobals(dest, src map[string]interface{}) map[string]interface{} {
}
}
} else if dv , ok := dg [ key ] ; ok && istable ( dv ) {
} else if dv , ok := dg [ key ] ; ok && istable ( dv ) {
// It's not clear if this condition can actually ever trigger.
// It's not clear if this condition can actually ever trigger.
log . Printf ( " key %s is table. Skipping", key )
log . Printf ( " Warning: For chart '%s', key ' %s' is a table. Skipping. ", chartName , key )
continue
continue
}
}
// TODO: Do we need to do any additional checking on the value?
// TODO: Do we need to do any additional checking on the value?
@ -291,7 +291,7 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf
// On error, we return just the overridden values.
// On error, we return just the overridden values.
// FIXME: We should log this error. It indicates that the YAML data
// FIXME: We should log this error. It indicates that the YAML data
// did not parse.
// did not parse.
return v , fmt . Errorf ( " error reading default values (%s): %s" , c . Values . Raw , err )
return v , fmt . Errorf ( " Error: Reading chart '%s' default values (%s): %s", c . Metadata . Name , c . Values . Raw , err )
}
}
for key , val := range nv {
for key , val := range nv {
@ -305,12 +305,12 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf
// if v[key] is a table, merge nv's val table into v[key].
// if v[key] is a table, merge nv's val table into v[key].
src , ok := val . ( map [ string ] interface { } )
src , ok := val . ( map [ string ] interface { } )
if ! ok {
if ! ok {
log . Printf ( " warning: skipped value for %s: Not a table." , key )
log . Printf ( " Warning: Building values map for chart '%s'. Skipped value (%+v) for '%s', as it is not a table.", c . Metadata . Name , src , key )
continue
continue
}
}
// Because v has higher precedence than nv, dest values override src
// Because v has higher precedence than nv, dest values override src
// values.
// values.
coalesceTables ( dest , src )
coalesceTables ( dest , src , c . Metadata . Name )
}
}
} else {
} else {
// If the key is not in v, copy it from nv.
// If the key is not in v, copy it from nv.
@ -323,7 +323,7 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf
// coalesceTables merges a source map into a destination map.
// coalesceTables merges a source map into a destination map.
//
//
// dest is considered authoritative.
// dest is considered authoritative.
func coalesceTables ( dst , src map [ string ] interface { } ) map [ string ] interface { } {
func coalesceTables ( dst , src map [ string ] interface { } , chartName string ) map [ string ] interface { } {
// Because dest has higher precedence than src, dest values override src
// Because dest has higher precedence than src, dest values override src
// values.
// values.
for key , val := range src {
for key , val := range src {
@ -331,13 +331,13 @@ func coalesceTables(dst, src map[string]interface{}) map[string]interface{} {
if innerdst , ok := dst [ key ] ; ! ok {
if innerdst , ok := dst [ key ] ; ! ok {
dst [ key ] = val
dst [ key ] = val
} else if istable ( innerdst ) {
} else if istable ( innerdst ) {
coalesceTables ( innerdst . ( map [ string ] interface { } ) , val . ( map [ string ] interface { } ) )
coalesceTables ( innerdst . ( map [ string ] interface { } ) , val . ( map [ string ] interface { } ) , chartName )
} else {
} else {
log . Printf ( " warning: cannot overwrite table with non table for %s (%v)" , key , val )
log . Printf ( " Warning: Merging destination map for chart '%s'. Cannot overwrite table item '%s', with non table value: %v", chartName , key , val )
}
}
continue
continue
} else if dv , ok := dst [ key ] ; ok && istable ( dv ) {
} else if dv , ok := dst [ key ] ; ok && istable ( dv ) {
log . Printf ( " warning: destination for %s is a table. Ignoring non-table value %v" , key , val )
log . Printf ( " Warning: Merging destination map for chart '%s'. The destination item '%s' is a table and ignoring the source '%s' as it has a non-table value of: %v", chartName , key , key , val )
continue
continue
} else if ! ok { // <- ok is still in scope from preceding conditional.
} else if ! ok { // <- ok is still in scope from preceding conditional.
dst [ key ] = val
dst [ key ] = val