Skip to content

Commit

Permalink
fix(tiller): return yaml parsing errors
Browse files Browse the repository at this point in the history
closes: #1519
  • Loading branch information
adamreese committed Nov 14, 2016
1 parent 915769b commit e2ab407
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions pkg/chartutil/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,44 +146,54 @@ func CoalesceValues(chrt *chart.Chart, vals *chart.Config) (Values, error) {
if err != nil {
return cvals, err
}
cvals = coalesce(chrt, evals)
cvals, err = coalesce(chrt, evals)
if err != nil {
return cvals, err
}
}

cvals = coalesceDeps(chrt, cvals)

return cvals, nil
var err error
cvals, err = coalesceDeps(chrt, cvals)
return cvals, err
}

// coalesce coalesces the dest values and the chart values, giving priority to the dest values.
//
// This is a helper function for CoalesceValues.
func coalesce(ch *chart.Chart, dest map[string]interface{}) map[string]interface{} {
dest = coalesceValues(ch, dest)
func coalesce(ch *chart.Chart, dest map[string]interface{}) (map[string]interface{}, error) {
var err error
dest, err = coalesceValues(ch, dest)
if err != nil {
return dest, err
}
coalesceDeps(ch, dest)
return dest
return dest, nil
}

// coalesceDeps coalesces the dependencies of the given chart.
func coalesceDeps(chrt *chart.Chart, dest map[string]interface{}) map[string]interface{} {
func coalesceDeps(chrt *chart.Chart, dest map[string]interface{}) (map[string]interface{}, error) {
for _, subchart := range chrt.Dependencies {
if c, ok := dest[subchart.Metadata.Name]; !ok {
// If dest doesn't already have the key, create it.
dest[subchart.Metadata.Name] = map[string]interface{}{}
} else if !istable(c) {
log.Printf("error: type mismatch on %s: %t", subchart.Metadata.Name, c)
return dest
return dest, fmt.Errorf("type mismatch on %s: %t", subchart.Metadata.Name, c)
}
if dv, ok := dest[subchart.Metadata.Name]; ok {
dvmap := dv.(map[string]interface{})

// Get globals out of dest and merge them into dvmap.
coalesceGlobals(dvmap, dest)

var err error
// Now coalesce the rest of the values.
dest[subchart.Metadata.Name] = coalesce(subchart, dvmap)
dest[subchart.Metadata.Name], err = coalesce(subchart, dvmap)
if err != nil {
return dest, err
}
}
}
return dest
return dest, nil
}

// coalesceGlobals copies the globals out of src and merges them into dest.
Expand Down Expand Up @@ -228,19 +238,18 @@ func coalesceGlobals(dest, src map[string]interface{}) map[string]interface{} {
// coalesceValues builds up a values map for a particular chart.
//
// Values in v will override the values in the chart.
func coalesceValues(c *chart.Chart, v map[string]interface{}) map[string]interface{} {
func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interface{}, error) {
// If there are no values in the chart, we just return the given values
if c.Values == nil || c.Values.Raw == "" {
return v
return v, nil
}

nv, err := ReadValues([]byte(c.Values.Raw))
if err != nil {
// On error, we return just the overridden values.
// FIXME: We should log this error. It indicates that the YAML data
// did not parse.
log.Printf("error reading default values (%s): %s", c.Values.Raw, err)
return v
return v, fmt.Errorf("error reading default values (%s): %s", c.Values.Raw, err)
}

for key, val := range nv {
Expand All @@ -259,7 +268,7 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) map[string]interfa
coalesceTables(dest, src)
}
}
return v
return v, nil
}

// coalesceTables merges a source map into a destination map.
Expand Down

0 comments on commit e2ab407

Please sign in to comment.