diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 9e6a0c434..30ee2722b 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -74,6 +74,11 @@ func TestTemplateCmd(t *testing.T) { cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/chart-with-template-lib-archive-dep"), golden: "output/template-chart-with-template-lib-archive-dep.txt", }, + { + name: "check kube version", + cmd: fmt.Sprintf("template --kube-version 1.16.0 '%s'", chartPath), + golden: "output/template-with-kube-version.txt", + }, { name: "check kube api versions", cmd: fmt.Sprintf("template --api-versions helm.k8s.io/test '%s'", chartPath), diff --git a/cmd/helm/testdata/output/template-with-kube-version.txt b/cmd/helm/testdata/output/template-with-kube-version.txt new file mode 100644 index 000000000..84397a15a --- /dev/null +++ b/cmd/helm/testdata/output/template-with-kube-version.txt @@ -0,0 +1,84 @@ +--- +# Source: subchart/templates/subdir/serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: subchart-sa +--- +# Source: subchart/templates/subdir/role.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: subchart-role +rules: +- resources: ["*"] + verbs: ["get","list","watch"] +--- +# Source: subchart/templates/subdir/rolebinding.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: subchart-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: subchart-role +subjects: +- kind: ServiceAccount + name: subchart-sa + namespace: default +--- +# Source: subchart/charts/subcharta/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: subcharta + labels: + helm.sh/chart: "subcharta-0.1.0" +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: 80 + protocol: TCP + name: apache + selector: + app.kubernetes.io/name: subcharta +--- +# Source: subchart/charts/subchartb/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: subchartb + labels: + helm.sh/chart: "subchartb-0.1.0" +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: 80 + protocol: TCP + name: nginx + selector: + app.kubernetes.io/name: subchartb +--- +# Source: subchart/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: subchart + labels: + helm.sh/chart: "subchart-0.1.0" + app.kubernetes.io/instance: "RELEASE-NAME" + kube-version/major: "1" + kube-version/minor: "16" + kube-version/version: "v1.16.0" +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: 80 + protocol: TCP + name: nginx + selector: + app.kubernetes.io/name: subchart diff --git a/pkg/chartutil/capabilities.go b/pkg/chartutil/capabilities.go index f9a454ad6..190744665 100644 --- a/pkg/chartutil/capabilities.go +++ b/pkg/chartutil/capabilities.go @@ -81,7 +81,7 @@ func ParseKubeVersion(version string) (*KubeVersion, error) { return nil, err } return &KubeVersion{ - Version: sv.Original(), + Version: "v" + sv.String(), Major: strconv.FormatUint(sv.Major(), 10), Minor: strconv.FormatUint(sv.Minor(), 10), }, nil diff --git a/pkg/chartutil/capabilities_test.go b/pkg/chartutil/capabilities_test.go index 7134abfc5..a68d16b45 100644 --- a/pkg/chartutil/capabilities_test.go +++ b/pkg/chartutil/capabilities_test.go @@ -66,3 +66,19 @@ func TestDefaultCapabilitiesHelmVersion(t *testing.T) { t.Errorf("Expected default HelmVersion to be v3.5, got %q", hv.Version) } } + +func TestParseKubeVersion(t *testing.T) { + kv, err := ParseKubeVersion("v1.16.0") + if err != nil { + t.Errorf("Expected v1.16.0 to parse successfully") + } + if kv.Version != "v1.16.0" { + t.Errorf("Expected parsed KubeVersion.Version to be v1.16.0, got %q", kv.String()) + } + if kv.Major != "1" { + t.Errorf("Expected parsed KubeVersion.Major to be 1, got %q", kv.Major) + } + if kv.Minor != "16" { + t.Errorf("Expected parsed KubeVersion.Minor to be 16, got %q", kv.Minor) + } +}