From 26b4cfc4358191e941357dbdfedaff65d2a47edd Mon Sep 17 00:00:00 2001 From: John Shields Date: Thu, 26 Jul 2018 15:49:02 -0500 Subject: [PATCH] Issue #836: Use releaseName to get release info. The helm release name can be templated so within the `deployRelease` function the `releaseName` variable should be used any time the release name is desired. This commit updates the final call to `getDeployResults` to properly use the `releaseName` variable. --- pkg/skaffold/deploy/helm.go | 2 +- pkg/skaffold/deploy/helm_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index ff95dec7e55..428b0ec888a 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -236,7 +236,7 @@ func (h *HelmDeployer) deployRelease(out io.Writer, r v1alpha2.HelmRelease, buil args = append(args, setOpts...) helmErr := h.helm(out, args...) - return h.getDeployResults(ns, r.Name), helmErr + return h.getDeployResults(ns, releaseName), helmErr } // imageName if the given string includes a fully qualified docker image name then lets trim just the tag part out diff --git a/pkg/skaffold/deploy/helm_test.go b/pkg/skaffold/deploy/helm_test.go index 19023c87d7d..1a3d1806618 100644 --- a/pkg/skaffold/deploy/helm_test.go +++ b/pkg/skaffold/deploy/helm_test.go @@ -24,6 +24,7 @@ import ( "io/ioutil" "os" "os/exec" + "strings" "testing" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" @@ -93,6 +94,24 @@ var testDeployFooWithPackaged = &v1alpha2.HelmDeploy{ }, } +var testDeployWithTemplatedName = &v1alpha2.HelmDeploy{ + Releases: []v1alpha2.HelmRelease{ + { + Name: "{{.USER}}-skaffold-helm", + ChartPath: "examples/test", + Values: map[string]string{ + "image.tag": "skaffold-helm", + }, + Overrides: map[string]interface{}{ + "foo": "bar", + }, + SetValues: map[string]string{ + "some.key": "somevalue", + }, + }, + }, +} + var testNamespace = "testNamespace" var validDeployYaml = ` @@ -267,6 +286,12 @@ func TestHelmDeploy(t *testing.T) { ), builds: testBuildsFoo, }, + { + description: "deploy and get templated release name", + cmd: &MockHelm{t: t}, + deployer: NewHelmDeployer(testDeployWithTemplatedName, testKubeContext, testNamespace), + builds: testBuilds, + }, } for _, tt := range tests { @@ -306,6 +331,12 @@ func (m *MockHelm) RunCmd(c *exec.Cmd) error { m.t.Errorf("Invalid kubernetes context %v", c) } + if c.Args[3] == "get" || c.Args[3] == "upgrade" { + if releaseName := c.Args[4]; strings.Contains(releaseName, "{{") { + m.t.Errorf("Invalid release name: %v", releaseName) + } + } + switch c.Args[3] { case "get": return m.getResult