From 62f85322ef114089724835e545d8d32d9bc30e12 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 11 Apr 2018 14:46:18 -0700 Subject: [PATCH 1/6] Update helm template -x to support children chart manifests in more cases The previous code validated the manifests exist within the file system, which only works when a chart is unpacked, meaning children charts stored as tgz's in the parent chart's `charts/` directory don't exist as individual files in the filesystem, causing validation to file. Instead, we validate against the paths within the chart itself rather than the filesystem, handling both chart.tgz's and charts that are unpacked as directories in the chart/ directory. --- cmd/helm/template.go | 78 ++++++++++++++++++++------------------- cmd/helm/template_test.go | 7 ++++ 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/cmd/helm/template.go b/cmd/helm/template.go index c04bc2dc8..fc1f44392 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -117,31 +117,10 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { } else { return err } - // verify specified templates exist relative to chart - rf := []string{} - var af string - var err error - if len(t.renderFiles) > 0 { - for _, f := range t.renderFiles { - if !filepath.IsAbs(f) { - af, err = filepath.Abs(filepath.Join(t.chartPath, f)) - if err != nil { - return fmt.Errorf("could not resolve template path: %s", err) - } - } else { - af = f - } - rf = append(rf, af) - - if _, err := os.Stat(af); err != nil { - return fmt.Errorf("could not resolve template path: %s", err) - } - } - } // verify that output-dir exists if provided if t.outputDir != "" { - _, err = os.Stat(t.outputDir) + _, err := os.Stat(t.outputDir) if os.IsNotExist(err) { return fmt.Errorf("output-dir '%s' does not exist", t.outputDir) } @@ -232,19 +211,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { m := tiller.Manifest{Name: k, Content: v, Head: &util.SimpleHead{Kind: h}} listManifests = append(listManifests, m) } - in := func(needle string, haystack []string) bool { - // make needle path absolute - d := strings.Split(needle, string(os.PathSeparator)) - dd := d[1:] - an := filepath.Join(t.chartPath, strings.Join(dd, string(os.PathSeparator))) - - for _, h := range haystack { - if h == an { - return true - } - } - return false - } + if settings.Debug { rel := &release.Release{ Name: t.releaseName, @@ -257,10 +224,45 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { printRelease(os.Stdout, rel) } - for _, m := range tiller.SortByKind(listManifests) { - if len(t.renderFiles) > 0 && !in(m.Name, rf) { - continue + var manifestsToRender []tiller.Manifest + + // if we have a list of files to render, then check that each of the + // provided files exists in the chart. + if len(t.renderFiles) > 0 { + for _, f := range t.renderFiles { + missing := true + if !filepath.IsAbs(f) { + newF, err := filepath.Abs(filepath.Join(t.chartPath, f)) + if err != nil { + return fmt.Errorf("could not turn template path %s into absolute path: %s", f, err) + } + f = newF + } + + for _, manifest := range listManifests { + manifestPathSplit := strings.Split(manifest.Name, string(filepath.Separator)) + // remove the chart name from the path + manifestPathSplit = manifestPathSplit[1:] + toJoin := append([]string{t.chartPath}, manifestPathSplit...) + manifestPath := filepath.Join(toJoin...) + + // if the filepath provided matches a manifest path in the + // chart, render that manifest + if f == manifestPath { + manifestsToRender = append(manifestsToRender, manifest) + missing = false + } + } + if missing { + return fmt.Errorf("could not find template %s in chart", f) + } } + } else { + // no renderFiles provided, render all manifests in the chart + manifestsToRender = listManifests + } + + for _, m := range tiller.SortByKind(manifestsToRender) { data := m.Content b := filepath.Base(m.Name) if !t.showNotes && b == "NOTES.txt" { diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index eefa46774..bbcc9f3af 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -69,6 +69,13 @@ func TestTemplateCmd(t *testing.T) { expectKey: "subchart1/templates/service.yaml", expectValue: "protocol: TCP\n name: apache", }, + { + name: "check_execute_subchart_template", + desc: "verify --execute single template on a subchart template", + args: []string{chartPath, "-x", "charts/subcharta/templates/service.yaml", "--set", "subcharta.service.name=foobar"}, + expectKey: "subchart1/charts/subcharta/templates/service.yaml", + expectValue: "protocol: TCP\n name: foobar", + }, { name: "check_namespace", desc: "verify --namespace", From d7e71709935b2f3b93c90c85ecdbf3d247cc7ebf Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 11 Apr 2018 16:26:15 -0700 Subject: [PATCH 2/6] Add working template to mariner chart for use in testing subcharts --- pkg/chartutil/testdata/frobnitz-1.2.3.tgz | Bin 2070 -> 3654 bytes .../frobnitz/charts/mariner-4.3.2.tgz | Bin 1034 -> 1012 bytes .../mariner/charts/albatross-0.1.0.tgz | Bin 347 -> 292 bytes .../mariner/templates/placeholder.tpl | 2 ++ 4 files changed, 2 insertions(+) diff --git a/pkg/chartutil/testdata/frobnitz-1.2.3.tgz b/pkg/chartutil/testdata/frobnitz-1.2.3.tgz index fb21cd08fb08fd2f4e45e940634ce1cdb0421457..cd12d2c1ef7d96805820389c38a21d03add7f06d 100644 GIT binary patch literal 3654 zcmV-M4!Q9kiwFR5n9f=N1MOT3eA84H-+ti4f}qF;D$HFn{Rzs_cgxCnOg4}=Y`kAv z+T5*SX;YGPUBNK~kqPn;KINs;!KWZ^##B&n2r4=RR1i@ZQxPVQjhD(mpx;f>m90D~ z&=t`9e~hHL=RT5?bMCq4oSQV3G21DAj54hDpi-%fdOZ-22I;8M=%k|;K&{mnv^t$Z ztP;|UfG#bPDw7IQsL^W?|MfbpDh#NCJ&>#6U(SDt<4VQt9*2zE1E2hN zwh}Cly9pZ|^gaT~zd@_^)Bk#nRx8VYC_p%+6a zDt5-qknS3lIL66ZptnaW&pSAiQdx~anZ__mGr=mXjL@<`QIkMHS%iDOT2+HC%b>#@ z_H+edw=+B;JUX!_n8mXMdO9ZQER&#}!Z-;;WQD9);60a$Ld1Wc{96S1=W4|a{CoCa z_4!|?H)>`3FBI_cpJXhx!~L7$zea16`5y}S_%En5oXbqFg+2n!|9XSLpZ`XKQJ()p zfw+!YHX3-R@%CsIS79AHDB{qI08jy%y3kpB%sU0TTrS+D#ThnTsX;fXL}i#nc3l#2 zI+j|?qA7dE)ri%xv9U_AR3fi2BH*G(-r641=nWXM0jP8<@BKlM?J*v5Jk|l#iWAJ0 z4vEri41^atPAOgz%2;UOMe;O?Mf4yGwSWP)_`kP#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wti^nk)EvUsolQ}TKhoH^`Tah5&VKqp@FnN`?~EI5yvGmVv;1>iU*^A(0{Q~{uR`@o*M z%7&edw#^PUw8u^~=X1(x-;Xn!Wk0%GbA5)&B41Dtb&pGEL74_#ol>prTw=m`( zZL@bK9qp@cfp6q5bA|kGVa)$vTxZ)U9snQJf0Fvu`%medQ2%dX$UhbD7&<%4vW@eV tab?Ds>0<3e$rj$(uw88|syhGx0000000000006*m_5v>lSt Date: Wed, 11 Apr 2018 16:28:14 -0700 Subject: [PATCH 3/6] test helm template -x against subcharts stored as tgz's --- cmd/helm/template_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index bbcc9f3af..46adecca7 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -27,7 +27,10 @@ import ( "testing" ) -var chartPath = "./../../pkg/chartutil/testdata/subpop/charts/subchart1" +var ( + chartPath = "./../../pkg/chartutil/testdata/subpop/charts/subchart1" + frobnitzChartPath = "./../../pkg/chartutil/testdata/frobnitz" +) func TestTemplateCmd(t *testing.T) { absChartPath, err := filepath.Abs(chartPath) @@ -76,6 +79,13 @@ func TestTemplateCmd(t *testing.T) { expectKey: "subchart1/charts/subcharta/templates/service.yaml", expectValue: "protocol: TCP\n name: foobar", }, + { + name: "check_execute_subchart_template_for_tgz_subchart", + desc: "verify --execute single template on a subchart template where the subchart is a .tgz in the chart directory", + args: []string{frobnitzChartPath, "-x", "charts/mariner/templates/placeholder.tpl", "--set", "mariner.name=moon"}, + expectKey: "frobnitz/charts/mariner/templates/placeholder.tpl", + expectValue: "Goodbye moon", + }, { name: "check_namespace", desc: "verify --namespace", From ced20f6f4ebacbc120cd7e580668e3797aa7f2a9 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 11 Apr 2018 16:28:56 -0700 Subject: [PATCH 4/6] Disambigutate chartPaths variables in helm template tests --- cmd/helm/template_test.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 46adecca7..d2469525e 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -28,12 +28,12 @@ import ( ) var ( - chartPath = "./../../pkg/chartutil/testdata/subpop/charts/subchart1" - frobnitzChartPath = "./../../pkg/chartutil/testdata/frobnitz" + subchart1ChartPath = "./../../pkg/chartutil/testdata/subpop/charts/subchart1" + frobnitzChartPath = "./../../pkg/chartutil/testdata/frobnitz" ) func TestTemplateCmd(t *testing.T) { - absChartPath, err := filepath.Abs(chartPath) + subchart1AbsChartPath, err := filepath.Abs(subchart1ChartPath) if err != nil { t.Fatal(err) } @@ -47,35 +47,35 @@ func TestTemplateCmd(t *testing.T) { { name: "check_name", desc: "check for a known name in chart", - args: []string{chartPath}, + args: []string{subchart1ChartPath}, expectKey: "subchart1/templates/service.yaml", expectValue: "protocol: TCP\n name: nginx", }, { name: "check_set_name", desc: "verify --set values exist", - args: []string{chartPath, "-x", "templates/service.yaml", "--set", "service.name=apache"}, + args: []string{subchart1ChartPath, "-x", "templates/service.yaml", "--set", "service.name=apache"}, expectKey: "subchart1/templates/service.yaml", expectValue: "protocol: TCP\n name: apache", }, { name: "check_execute", desc: "verify --execute single template", - args: []string{chartPath, "-x", "templates/service.yaml", "--set", "service.name=apache"}, + args: []string{subchart1ChartPath, "-x", "templates/service.yaml", "--set", "service.name=apache"}, expectKey: "subchart1/templates/service.yaml", expectValue: "protocol: TCP\n name: apache", }, { name: "check_execute_absolute", desc: "verify --execute single template", - args: []string{chartPath, "-x", absChartPath + "/" + "templates/service.yaml", "--set", "service.name=apache"}, + args: []string{subchart1ChartPath, "-x", subchart1AbsChartPath + "/" + "templates/service.yaml", "--set", "service.name=apache"}, expectKey: "subchart1/templates/service.yaml", expectValue: "protocol: TCP\n name: apache", }, { name: "check_execute_subchart_template", desc: "verify --execute single template on a subchart template", - args: []string{chartPath, "-x", "charts/subcharta/templates/service.yaml", "--set", "subcharta.service.name=foobar"}, + args: []string{subchart1ChartPath, "-x", "charts/subcharta/templates/service.yaml", "--set", "subcharta.service.name=foobar"}, expectKey: "subchart1/charts/subcharta/templates/service.yaml", expectValue: "protocol: TCP\n name: foobar", }, @@ -89,42 +89,42 @@ func TestTemplateCmd(t *testing.T) { { name: "check_namespace", desc: "verify --namespace", - args: []string{chartPath, "--namespace", "test"}, + args: []string{subchart1ChartPath, "--namespace", "test"}, expectKey: "subchart1/templates/service.yaml", expectValue: "namespace: \"test\"", }, { name: "check_release_name", desc: "verify --release exists", - args: []string{chartPath, "--name", "test"}, + args: []string{subchart1ChartPath, "--name", "test"}, expectKey: "subchart1/templates/service.yaml", expectValue: "release-name: \"test\"", }, { name: "check_notes", desc: "verify --notes shows notes", - args: []string{chartPath, "--notes", "true"}, + args: []string{subchart1ChartPath, "--notes", "true"}, expectKey: "subchart1/templates/NOTES.txt", expectValue: "Sample notes for subchart1", }, { name: "check_values_files", desc: "verify --values files values exist", - args: []string{chartPath, "--values", chartPath + "/charts/subchartA/values.yaml"}, + args: []string{subchart1ChartPath, "--values", subchart1ChartPath + "/charts/subchartA/values.yaml"}, expectKey: "subchart1/templates/service.yaml", expectValue: "name: apache", }, { name: "check_name_template", desc: "verify --name-template result exists", - args: []string{chartPath, "--name-template", "foobar-{{ b64enc \"abc\" }}-baz"}, + args: []string{subchart1ChartPath, "--name-template", "foobar-{{ b64enc \"abc\" }}-baz"}, expectKey: "subchart1/templates/service.yaml", expectValue: "release-name: \"foobar-YWJj-baz\"", }, { name: "check_kube_version", desc: "verify --kube-version overrides the kubernetes version", - args: []string{chartPath, "--kube-version", "1.6"}, + args: []string{subchart1ChartPath, "--kube-version", "1.6"}, expectKey: "subchart1/templates/service.yaml", expectValue: "kube-version/major: \"1\"\n kube-version/minor: \"6\"\n kube-version/gitversion: \"v1.6.0\"", }, From b9adc356e8d1fe68b139a0b4c2495aa1e5fdebf8 Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 11 Apr 2018 16:46:24 -0700 Subject: [PATCH 5/6] Correctly use subtests in helm template tests The testing.T in the subtest wasn't being used, so subtests were effectively not being used. Additionally, in case subtests run in parallel, we assign tt := tt to fix closure captures on range variables, since the variables produced by a range are re-used between iterations. --- cmd/helm/template_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index d2469525e..7505b0474 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -132,7 +132,8 @@ func TestTemplateCmd(t *testing.T) { var buf bytes.Buffer for _, tt := range tests { - t.Run(tt.name, func(T *testing.T) { + tt := tt + t.Run(tt.name, func(t *testing.T) { // capture stdout old := os.Stdout r, w, _ := os.Pipe() From fb1dd48b5a1994e8a81a9b734cb6503d024799cd Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Wed, 11 Apr 2018 16:48:53 -0700 Subject: [PATCH 6/6] test helm template -x with non-existent manifest --- cmd/helm/template_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 7505b0474..68ed87cd2 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -43,6 +43,7 @@ func TestTemplateCmd(t *testing.T) { args []string expectKey string expectValue string + expectError string }{ { name: "check_name", @@ -65,6 +66,12 @@ func TestTemplateCmd(t *testing.T) { expectKey: "subchart1/templates/service.yaml", expectValue: "protocol: TCP\n name: apache", }, + { + name: "check_execute_non_existent", + desc: "verify --execute fails on a template that doesnt exist", + args: []string{subchart1ChartPath, "-x", "templates/thisdoesntexist.yaml"}, + expectError: "could not find template", + }, { name: "check_execute_absolute", desc: "verify --execute single template", @@ -143,8 +150,21 @@ func TestTemplateCmd(t *testing.T) { cmd := newTemplateCmd(out) cmd.SetArgs(tt.args) err := cmd.Execute() - if err != nil { - t.Errorf("expected: %v, got %v", tt.expectValue, err) + + if tt.expectError != "" { + if err == nil { + t.Errorf("expected err: %s, but no error occurred", tt.expectError) + } + // non nil error, check if it contains the expected error + if strings.Contains(err.Error(), tt.expectError) { + // had the error we were looking for, this test case is + // done + return + } else { + t.Fatalf("expected err: %q, got: %q", tt.expectError, err) + } + } else if err != nil { + t.Errorf("expected no error, got %v", err) } // restore stdout w.Close()