From d5a865b5f4fe5392defb7aba40711aa8135933a8 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Tue, 16 Jan 2018 13:02:30 -0500 Subject: [PATCH] fix(capabilities): Adding GitVersion to default set Prior to this, using the semver template functions with the full version, which is represented in the GitVersion, was not possible for helm template and lint commands because the property was not populated by default. This update adds default handling. Closes #3349 --- cmd/helm/template.go | 1 + cmd/helm/template_test.go | 2 +- pkg/chartutil/capabilities.go | 11 ++++++----- .../subpop/charts/subchart1/templates/service.yaml | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/helm/template.go b/cmd/helm/template.go index c83779a31..aba3c3ffe 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -203,6 +203,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { } caps.KubeVersion.Major = fmt.Sprint(kv.Major()) caps.KubeVersion.Minor = fmt.Sprint(kv.Minor()) + caps.KubeVersion.GitVersion = fmt.Sprintf("v%d.%d.0", kv.Major(), kv.Minor()) } vals, err := chartutil.ToRenderValuesCaps(c, config, options, caps) if err != nil { diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index e3b85e97c..eefa46774 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -109,7 +109,7 @@ func TestTemplateCmd(t *testing.T) { desc: "verify --kube-version overrides the kubernetes version", args: []string{chartPath, "--kube-version", "1.6"}, expectKey: "subchart1/templates/service.yaml", - expectValue: "kube-version/major: \"1\"\n kube-version/minor: \"6\"", + expectValue: "kube-version/major: \"1\"\n kube-version/minor: \"6\"\n kube-version/gitversion: \"v1.6.0\"", }, } diff --git a/pkg/chartutil/capabilities.go b/pkg/chartutil/capabilities.go index 82478e6ea..c87c0368e 100644 --- a/pkg/chartutil/capabilities.go +++ b/pkg/chartutil/capabilities.go @@ -29,11 +29,12 @@ var ( // DefaultKubeVersion is the default kubernetes version DefaultKubeVersion = &version.Info{ - Major: "1", - Minor: "9", - GoVersion: runtime.Version(), - Compiler: runtime.Compiler, - Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + Major: "1", + Minor: "9", + GitVersion: "v1.9.0", + GoVersion: runtime.Version(), + Compiler: runtime.Compiler, + Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), } ) diff --git a/pkg/chartutil/testdata/subpop/charts/subchart1/templates/service.yaml b/pkg/chartutil/testdata/subpop/charts/subchart1/templates/service.yaml index 8b6bbaee7..3835a3d0b 100644 --- a/pkg/chartutil/testdata/subpop/charts/subchart1/templates/service.yaml +++ b/pkg/chartutil/testdata/subpop/charts/subchart1/templates/service.yaml @@ -8,6 +8,7 @@ metadata: release-name: "{{ .Release.Name }}" kube-version/major: "{{ .Capabilities.KubeVersion.Major }}" kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}" + kube-version/gitversion: "v{{ .Capabilities.KubeVersion.Major }}.{{ .Capabilities.KubeVersion.Minor }}.0" spec: type: {{ .Values.service.type }} ports: