From b305a501e84d4a6a4a881b3550bcd6b2d7424490 Mon Sep 17 00:00:00 2001 From: Ashmit Bhardwaj Date: Thu, 13 Mar 2025 13:28:21 +0000 Subject: [PATCH] added documentation and test cases for api-versions flag Signed-off-by: Ashmit Bhardwaj --- pkg/cmd/template.go | 2 +- pkg/cmd/template_test.go | 7 ++++++- .../output/template-with-api-version.txt | 1 + .../issue-7233/charts/alpine-0.1.0.tgz | Bin 0 -> 1166 bytes .../testcharts/subchart/templates/service.yaml | 3 +++ 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 pkg/cmd/testdata/testcharts/issue-7233/charts/alpine-0.1.0.tgz diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 7a565ef85..bb0319264 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -201,7 +201,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&skipTests, "skip-tests", false, "skip tests from templated output") f.BoolVar(&client.IsUpgrade, "is-upgrade", false, "set .Release.IsUpgrade instead of .Release.IsInstall") f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for Capabilities.KubeVersion") - f.StringSliceVarP(&extraAPIs, "api-versions", "a", []string{}, "Kubernetes api versions used for Capabilities.APIVersions") + f.StringSliceVarP(&extraAPIs, "api-versions", "a", []string{}, "Kubernetes api versions used for Capabilities.APIVersions ( Can specify multiple or separate values with commands. Example --api-versions value1 --api-versions value2 or --api-versions value1, value2)") f.BoolVar(&client.UseReleaseName, "release-name", false, "use release name in the output-dir path.") bindPostRenderFlag(cmd, &client.PostRenderer) diff --git a/pkg/cmd/template_test.go b/pkg/cmd/template_test.go index a6c848e08..5bcccf5d0 100644 --- a/pkg/cmd/template_test.go +++ b/pkg/cmd/template_test.go @@ -83,7 +83,12 @@ func TestTemplateCmd(t *testing.T) { }, { name: "check kube api versions", - cmd: fmt.Sprintf("template --api-versions helm.k8s.io/test '%s'", chartPath), + cmd: fmt.Sprintf("template --api-versions helm.k8s.io/test,helm.k8s.io/test2 '%s'", chartPath), + golden: "output/template-with-api-version.txt", + }, + { + name: "check kube api versions", + cmd: fmt.Sprintf("template --api-versions helm.k8s.io/test --api-versions helm.k8s.io/test2 '%s'", chartPath), golden: "output/template-with-api-version.txt", }, { diff --git a/pkg/cmd/testdata/output/template-with-api-version.txt b/pkg/cmd/testdata/output/template-with-api-version.txt index 7e1c35001..8b6074cdb 100644 --- a/pkg/cmd/testdata/output/template-with-api-version.txt +++ b/pkg/cmd/testdata/output/template-with-api-version.txt @@ -75,6 +75,7 @@ metadata: kube-version/minor: "20" kube-version/version: "v1.20.0" kube-api-version/test: v1 + kube-api-version/test2: v2 spec: type: ClusterIP ports: diff --git a/pkg/cmd/testdata/testcharts/issue-7233/charts/alpine-0.1.0.tgz b/pkg/cmd/testdata/testcharts/issue-7233/charts/alpine-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..87db21817badafc36ad9eb7b7a12e35261c72202 GIT binary patch literal 1166 zcmV;91abQxiwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PI-XZsRr+&b6LmpuJto@+rakF8FtWf6;caNQ(uEqNvBx*djua zDoI&!y?*zC2RX6QO$v1F^q{#BM3En7hV#t~g}h>dhW{&2nPiJ4zxeu+rfGUPow{e5 zrrl>cp3N>s)2qwrY&M!)rWfgGJe^%$KzagQ9!aeYs*Ch5@6|Q#A0k+>Poy-HVh)>8 zgjIETjVH;QILb+9idDu9y`_rFEg&pWvkb0X@W8iB)OS$HJSt>Kb100d^n5rhh?j{j z+%pnrKlyNrw5(M|dL9i9lh@1?^)kt1>E`=In^u=J86|1-($4x9O5pznc}@C63E(;Y zr{lEC|EqM|^Zy+3!O^nZ4gxb@TAyCdD}n!p%8H{QJ@f;EO6FfJ8$84R@nkyg@P9U) z_WVDKbn5>t6ZsrI$~-E`V2%do5rD7V@otyg5GT}>*tD_V4|cocldl|pAdUbyE{SWq z4B!>~P!PmeRmp9=Bqhj@PM92)C~!^rV7ZO`0$>_yO*t3|MqzdfO~JAPjFdb;<*xal z91zxQLjp3_w8DE67O!d!E2#kUk_in>A)!HGETkrara%**ls7{ILWRn(tmdfPUKUD` zuB6ax$;sj+ZqZXV%;AA+z9+R|8Np}xwU&lpzkk{lOlX55qZl$NHY9AP1ts2+24;Xz zZ=FvV0k(PvKqCP;2e|@M5PWk$wFdYG3rv9q8d3zAA~e={+L`QEbsh30Q(GO647Eqz zwes=OLkqXtLE^6&*M}zap>vpiY&F(7Gya^R*0>G|wvDCx-~-bm--o4t58L>_1n^ys zGvX+0BVAEuBR1%v3)yHWWMg%xwe`GaWyQ%OBz{)II0r7}tq(e=P;1HuO!!$2E4jF;I0;hp8*SpL9n>* zK^KrSMVXOm+olSe*EXcKt&&!kw#-4pOaT~WvbLY(%2qfm$&k`5_=5}X0#=OEJ@BJ! zt6f63d2-R|h8NH(nMBc#vW5%=xZ=n;n1_z=rh9YS3CZwa@k<~3K?48j&M5rlM1KLE zz5h=p9sW;8qfyWQbBG~rYz_AR0bCdid>H(FVzigjN#MV222Vx*Kf(X*{eN;bzUujZ g4msw(4TGNkz4X#cFaHJkJpcgz|4sJjy8s{n0PDUu(*OVf literal 0 HcmV?d00001 diff --git a/pkg/cmd/testdata/testcharts/subchart/templates/service.yaml b/pkg/cmd/testdata/testcharts/subchart/templates/service.yaml index fee94dced..19c931cc3 100644 --- a/pkg/cmd/testdata/testcharts/subchart/templates/service.yaml +++ b/pkg/cmd/testdata/testcharts/subchart/templates/service.yaml @@ -11,6 +11,9 @@ metadata: {{- if .Capabilities.APIVersions.Has "helm.k8s.io/test" }} kube-api-version/test: v1 {{- end }} +{{- if .Capabilities.APIVersions.Has "helm.k8s.io/test2" }} + kube-api-version/test2: v2 +{{- end }} spec: type: {{ .Values.service.type }} ports: