pull/12812/merge
Jesse Simpson 3 weeks ago committed by GitHub
commit 34e4b586c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,7 +18,7 @@ package util
import ( import (
"fmt" "fmt"
"log" "log/slog"
"maps" "maps"
"github.com/mitchellh/copystructure" "github.com/mitchellh/copystructure"
@ -47,7 +47,7 @@ func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, err
if err != nil { if err != nil {
return vals, err return vals, err
} }
return coalesce(log.Printf, chrt, valsCopy, "", false) return coalesce(slog.Warn, chrt, valsCopy, "", false)
} }
// MergeValues is used to merge the values in a chart and its subcharts. This // MergeValues is used to merge the values in a chart and its subcharts. This
@ -69,7 +69,7 @@ func MergeValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error)
if err != nil { if err != nil {
return vals, err return vals, err
} }
return coalesce(log.Printf, chrt, valsCopy, "", true) return coalesce(slog.Warn, chrt, valsCopy, "", true)
} }
func copyValues(vals map[string]interface{}) (Values, error) { func copyValues(vals map[string]interface{}) (Values, error) {
@ -263,11 +263,11 @@ func childChartMergeTrue(chrt *chart.Chart, key string, merge bool) bool {
// //
// 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{}) map[string]interface{} {
return coalesceTablesFullKey(log.Printf, dst, src, "", false) return coalesceTablesFullKey(slog.Warn, dst, src, "", false)
} }
func MergeTables(dst, src map[string]interface{}) map[string]interface{} { func MergeTables(dst, src map[string]interface{}) map[string]interface{} {
return coalesceTablesFullKey(log.Printf, dst, src, "", true) return coalesceTablesFullKey(slog.Warn, dst, src, "", true)
} }
// coalesceTablesFullKey merges a source map into a destination map. // coalesceTablesFullKey merges a source map into a destination map.
@ -300,7 +300,7 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, pref
} else { } else {
printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val) printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val)
} }
} else if istable(dv) && val != nil { } else if istable(dv) && val != nil && isNonEmptyString(val) && isNonEmptyTable(dv) {
printf("warning: destination for %s is a table. Ignoring non-table value (%v)", fullkey, val) printf("warning: destination for %s is a table. Ignoring non-table value (%v)", fullkey, val)
} }
} }

@ -717,6 +717,72 @@ func TestCoalesceValuesWarnings(t *testing.T) {
} }
func TestCoalesceValuesWarningsWithEmptyDefaultMaps(t *testing.T) {
c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "level1"},
Values: map[string]interface{}{
"something": map[string]interface{}{
"somethingElse": []interface{}{},
},
},
})
vals := map[string]interface{}{
"something": map[string]interface{}{
"somethingElse": map[string]interface{}{},
},
}
warnings := make([]string, 0)
printf := func(format string, v ...interface{}) {
t.Logf(format, v...)
warnings = append(warnings, fmt.Sprintf(format, v...))
}
_, err := coalesce(printf, c, vals, "", false)
if err != nil {
t.Fatal(err)
}
t.Logf("vals: %v", vals)
assert.NotContains(t, warnings, "warning: destination for level1.something.somethingElse is a table. Ignoring non-table value ([])")
}
func TestCoalesceValuesWarningsWithEmptyStringDefault(t *testing.T) {
c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "level1"},
Values: map[string]interface{}{
"auth": map[string]interface{}{
"existingSecret": "",
},
},
})
vals := map[string]interface{}{
"auth": map[string]interface{}{
"existingSecret": map[string]interface{}{
"name": "secretName",
},
},
}
warnings := make([]string, 0)
printf := func(format string, v ...interface{}) {
t.Logf(format, v...)
warnings = append(warnings, fmt.Sprintf(format, v...))
}
_, err := coalesce(printf, c, vals, "", false)
if err != nil {
t.Fatal(err)
}
t.Logf("vals: %v", vals)
assert.NotContains(t, warnings, "warning: destination for level1.auth.existingSecret is a table. Ignoring non-table value ()")
}
func TestConcatPrefix(t *testing.T) { func TestConcatPrefix(t *testing.T) {
assert.Equal(t, "b", concatPrefix("", "b")) assert.Equal(t, "b", concatPrefix("", "b"))
assert.Equal(t, "a.b", concatPrefix("a", "b")) assert.Equal(t, "a.b", concatPrefix("a", "b"))

@ -179,6 +179,20 @@ func istable(v interface{}) bool {
return ok return ok
} }
func isNonEmptyTable(val interface{}) bool {
table, ok := val.(map[string]interface{})
if !ok {
return false
}
return len(table) > 0
}
func isNonEmptyString(val interface{}) bool {
valueString := fmt.Sprintf("%v", val)
return valueString != ""
}
// PathValue takes a path that traverses a YAML structure and returns the value at the end of that path. // PathValue takes a path that traverses a YAML structure and returns the value at the end of that path.
// The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods. // The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods.
// Given the following YAML data the value at path "chapter.one.title" is "Loomings". // Given the following YAML data the value at path "chapter.one.title" is "Loomings".

Loading…
Cancel
Save