Skip to content

Commit

Permalink
Support templated release names in helm render
Browse files Browse the repository at this point in the history
  • Loading branch information
briandealwis committed Apr 29, 2021
1 parent 4106c53 commit a57a1ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pkg/skaffold/deploy/helm/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,13 @@ func (h *Deployer) Render(ctx context.Context, out io.Writer, builds []graph.Art
renderedManifests := new(bytes.Buffer)

for _, r := range h.Releases {
args := []string{"template", chartSource(r)}
releaseName, err := util.ExpandEnvTemplateOrFail(r.Name, nil)
if err != nil {
return userErr(fmt.Sprintf("cannot expand release name %q", r.Name), err)
}

args = append(args[:1], append([]string{r.Name}, args[1:]...)...)
args := []string{"template", chartSource(r)}
args = append(args[:1], append([]string{releaseName}, args[1:]...)...)

params, err := pairParamsToArtifacts(builds, r.ArtifactOverrides)
if err != nil {
Expand Down
22 changes: 18 additions & 4 deletions pkg/skaffold/deploy/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ func TestHelmDeploy(t *testing.T) {
force bool
shouldErr bool
expectedWarnings []string
envs map[string]string
expectedNamespaces []string
}{

Expand Down Expand Up @@ -1008,7 +1007,6 @@ func TestHelmCleanup(t *testing.T) {
namespace string
builds []graph.Artifact
expectedWarnings []string
envs map[string]string
}{
{
description: "helm3 cleanup success",
Expand Down Expand Up @@ -1263,10 +1261,10 @@ func TestHelmRender(t *testing.T) {
shouldErr bool
commands util.Command
helm latest_v1.HelmDeploy
env []string
outputFile string
expected string
builds []graph.Artifact
envs map[string]string
namespace string
}{
{
Expand Down Expand Up @@ -1324,6 +1322,22 @@ func TestHelmRender(t *testing.T) {
Tag: "skaffold-helm:tag1",
}},
},
{
description: "render with missing templated release name should fail",
shouldErr: true,
commands: testutil.CmdRunWithOutput("helm version --client", version31),
helm: testDeployWithTemplatedName,
builds: testBuilds,
},
{
description: "render with templated release name",
env: []string{"USER=user"},
commands: testutil.
CmdRunWithOutput("helm version --client", version31).
AndRun("helm --kube-context kubecontext template user-skaffold-helm examples/test --set-string image.tag=docker.io:5000/skaffold-helm:3605e7bc17cf46e53f4d81c4cbc24e5b4c495184 --set some.key=somevalue --kubeconfig kubeconfig"),
helm: testDeployWithTemplatedName,
builds: testBuilds,
},
{
description: "render with namespace",
shouldErr: false,
Expand Down Expand Up @@ -1396,7 +1410,7 @@ func TestHelmRender(t *testing.T) {
file = t.NewTempDir().Path(test.outputFile)
}

t.Override(&util.OSEnviron, func() []string { return []string{"FOO=FOOBAR"} })
t.Override(&util.OSEnviron, func() []string { return append([]string{"FOO=FOOBAR"}, test.env...) })
t.Override(&util.DefaultExecCommand, test.commands)
deployer, err := NewDeployer(&helmConfig{
namespace: test.namespace,
Expand Down

0 comments on commit a57a1ec

Please sign in to comment.