5

I have a question about.Capabilities.APIVersions.Has - I am not sure how it works I have the following function:

{{- define "fybrik.certManagerApiVersion" -}}
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1beta1" -}}
cert-manager.io/v1beta1
{{- else if .Capabilities.APIVersions.Has "cert-manager.io/v1alpha2" -}}
cert-manager.io/v1alpha2
{{- else if .Capabilities.APIVersions.Has "certmanager.k8s.io/v1alpha1" -}}
certmanager.k8s.io/v1alpha1
{{- else -}}
cert-manager.io/v1
{{- end -}}

kubectl api-versions shows:

cert-manager.io/v1
cert-manager.io/v1alpha2
cert-manager.io/v1alpha3
cert-manager.io/v1beta1

but I always get cert-manager.io/v1 as the api when the resource is generated using helm install command. I would expect the api would be cert-manager.io/v1beta1 and I wonder what am missing? Thanks

erez
  • 151
  • 2
  • 3
  • 9

2 Answers2

6

It depends what Helm command are you using.

helm template will use apiVersions from kubectl compiled (check here https://github.com/helm/helm/blob/main/go.mod#L43).

helm install will use apiVersions available from k8s server, use helm install --dry-run --debug to see rendering result.

Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
  • 3
    It is now also possible to pass api versions to the helm template as well: `helm template . --api-versions cert-manager.io/v1` – k3a Jun 20 '22 at 19:08
3

There is a preferred version your cluster will want.

$ kubectl get --raw /apis/cert-manager.io | python -m json.tool
{
    "apiVersion": "v1",
    "kind": "APIGroup",
    "name": "cert-manager.io",
    "preferredVersion": {
        "groupVersion": "cert-manager.io/v1",
        "version": "v1"
    },
    "versions": [
        {
            "groupVersion": "cert-manager.io/v1",
            "version": "v1"
        },
        {
            "groupVersion": "cert-manager.io/v1beta1",
            "version": "v1beta1"
        },
        {
            "groupVersion": "cert-manager.io/v1alpha3",
            "version": "v1alpha3"
        },
        {
            "groupVersion": "cert-manager.io/v1alpha2",
            "version": "v1alpha2"
        }
    ]
}
Tanveer Alam
  • 5,185
  • 4
  • 22
  • 43
jmcgrath207
  • 1,317
  • 2
  • 19
  • 31