Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support templated release names in helm render #5751

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

@aaron-prindle aaron-prindle Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is releaseName the only field that needs this change?

Wasn't sure if these fields referenced in our-docs/the-bug might need changes as well:
deploy.helm.releases.setValueTemplates
deploy.helm.releases.name
deploy.helm.releases.namespace

If so, perhaps we can add some Github Issues regarding the other required fixes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an excellent question — I looked for other uses of r.Name, but should have checked the others.

  • releases.namespace is expanded in releaseNamespace()
  • setValueTemplates is expanded in constructOverrideArgs()

So I think we're good.

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