Skip to content

Commit

Permalink
feat: add template support for chartPath (#8645)
Browse files Browse the repository at this point in the history
* feat: add template support for `chartPath`

* chore: add basic chartPath unit test
  • Loading branch information
aniskhan001 authored Apr 10, 2023
1 parent 8e23d94 commit 4c73c82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/skaffold/deploy/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ var testDeployEnvTemplateNamespacedConfig = latest.LegacyHelmDeploy{
}},
}

var testDeployWithTemplatedChartPath = latest.LegacyHelmDeploy{
Releases: []latest.HelmRelease{{
Name: "skaffold-helm",
ChartPath: "examples/{{.FOO}}",
Overrides: schemautil.HelmOverrides{Values: map[string]interface{}{"foo": "bar"}},
SetValues: map[string]string{
"some.key": "somevalue",
},
}},
}

var testDeployConfigRemoteRepo = latest.LegacyHelmDeploy{
Releases: []latest.HelmRelease{{
Name: "skaffold-helm",
Expand Down Expand Up @@ -1212,6 +1223,15 @@ func TestHelmRender(t *testing.T) {
helm: testDeployWithTemplatedName,
builds: testBuilds,
},
{
description: "render with templated chart path",
shouldErr: false,
commands: testutil.
CmdRun("helm --kube-context kubecontext dep build examples/FOOBAR --kubeconfig kubeconfig").
AndRun("helm --kube-context kubecontext template skaffold-helm examples/FOOBAR --post-renderer SKAFFOLD-BINARY --set some.key=somevalue --kubeconfig kubeconfig"),
helm: testDeployWithTemplatedChartPath,
builds: testBuilds,
},
{
description: "render with namespace",
shouldErr: false,
Expand Down
5 changes: 5 additions & 0 deletions pkg/skaffold/render/renderer/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func (h Helm) generateHelmManifests(ctx context.Context, builds []graph.Artifact
return nil, helm.UserErr(fmt.Sprintf("cannot expand release name %q", release.Name), err)
}

release.ChartPath, err = sUtil.ExpandEnvTemplateOrFail(release.ChartPath, nil)
if err != nil {
return nil, helm.UserErr(fmt.Sprintf("cannot expand chart path %q", release.ChartPath), err)
}

args := []string{"template", releaseName, helm.ChartSource(release)}
args = append(args, postRendererArgs...)
if release.Packaged == nil && release.Version != "" {
Expand Down

0 comments on commit 4c73c82

Please sign in to comment.