From e53613db3f386b8728ac3d6038b9d13eba9caece Mon Sep 17 00:00:00 2001 From: Stefan Deitmer Date: Thu, 25 Jul 2019 14:29:45 +0200 Subject: [PATCH] Fix subchart values not being deleted by setting value to nil in parent chart's values Signed-off-by: Stefan Deitmer --- .../testdata/moby/charts/spouter/values.yaml | 1 + pkg/chartutil/testdata/moby/values.yaml | 4 +++ pkg/chartutil/values.go | 5 +--- pkg/chartutil/values_test.go | 27 +++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/pkg/chartutil/testdata/moby/charts/spouter/values.yaml b/pkg/chartutil/testdata/moby/charts/spouter/values.yaml index f71d92a9f..36cdff290 100644 --- a/pkg/chartutil/testdata/moby/charts/spouter/values.yaml +++ b/pkg/chartutil/testdata/moby/charts/spouter/values.yaml @@ -1 +1,2 @@ scope: spouter +foo: bar \ No newline at end of file diff --git a/pkg/chartutil/testdata/moby/values.yaml b/pkg/chartutil/testdata/moby/values.yaml index ecf22b563..8cea245ce 100644 --- a/pkg/chartutil/testdata/moby/values.yaml +++ b/pkg/chartutil/testdata/moby/values.yaml @@ -22,3 +22,7 @@ web: httpGet: path: /api/v1/info port: atc + +# for testing deleting default values in sub charts +spouter: + foo: null \ No newline at end of file diff --git a/pkg/chartutil/values.go b/pkg/chartutil/values.go index 1b7ba7a81..f82b95950 100644 --- a/pkg/chartutil/values.go +++ b/pkg/chartutil/values.go @@ -170,10 +170,7 @@ func CoalesceValues(chrt *chart.Chart, vals *chart.Config) (Values, error) { if err != nil { return cvals, err } - cvals, err = coalesce(chrt, evals) - if err != nil { - return cvals, err - } + return coalesce(chrt, evals) } return coalesceDeps(chrt, cvals) diff --git a/pkg/chartutil/values_test.go b/pkg/chartutil/values_test.go index cf2d1360c..dfb38387e 100644 --- a/pkg/chartutil/values_test.go +++ b/pkg/chartutil/values_test.go @@ -475,6 +475,33 @@ func TestCoalesceTables(t *testing.T) { t.Errorf("Expected boat string, got %v", dst["boat"]) } } + +func TestCoalesceSubchart(t *testing.T) { + tchart := "testdata/moby" + c, err := LoadDir(tchart) + if err != nil { + t.Fatal(err) + } + + tvals := &chart.Config{} + + v, err := CoalesceValues(c, tvals) + if err != nil { + t.Fatal(err) + } + j, _ := json.MarshalIndent(v, "", " ") + t.Logf("Coalesced Values: %s", string(j)) + + subchartValues, ok := v["spouter"].(map[string]interface{}) + if !ok { + t.Errorf("Subchart values not found") + } + + if _, ok := subchartValues["foo"]; ok { + t.Errorf("Expected key foo to be removed, still present") + } +} + func TestPathValue(t *testing.T) { doc := ` title: "Moby Dick"