Skip to content

Is template function .Capabilities.APIVersions.has reliable using helm template? #10760

Closed

Description

@ebuildy

Output of helm version: v3.8.1

Output of kubectl version: v1.19.15

Cloud Provider/Platform (AKS, GKE, Minikube etc.): on premise (kubespray)

Deploy workflow: using argoCD (helm template)

Helm template snippet:

{{- if .Capabilities.APIVersions.Has "policy/v1" -}}
apiVersion: policy/v1
{{- else}}
apiVersion: policy/v1beta1
{{- end }}

Trouble

helm template --kube-version 1.19.0 --api-versions policy/v1beta1 . should display apiVersion: policy/v1beta1 but .Capabilities.APIVersions.Has "policy/v1" returns true. In my understanding, --kube-version 1.19.0 should make Helm , k8s 1.19.0 compatible.

helm install is OK, but argoCD is doing a helm template.

(I took the snippet from https://github.com/elastic/helm-charts/blob/main/elasticsearch/templates/poddisruptionbudget.yaml )

I see bitnami is doing this instead of relying on .Capabilities.APIVersions.Has function: https://github.com/bitnami/charts/blob/master/bitnami/common/templates/_capabilities.tpl#L65

{{/*
Return the appropriate apiVersion for poddisruptionbudget.
*/}}
{{- define "common.capabilities.policy.apiVersion" -}}
{{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
{{- print "policy/v1beta1" -}}
{{- else -}}
{{- print "policy/v1" -}}
{{- end -}}
{{- end -}}

Is template function .Capabilities.APIVersions.has reliable? or is it a bug on argoCD side?

Or should I use only Helm v3.5.X with kubernetes v1.19? (according https://github.com/helm/helm/blob/v3.5.4/go.mod#L47)

Activity

  1. bacongobbler commented on Mar 11, 2022

    @bacongobbler
    Member

    helm template does not reach out to a Kubernetes cluster. It uses whatever APIVersions the Kubernetes client provides unless you pass the --validate flag.

  2. ebuildy commented on Mar 11, 2022

    @ebuildy
    Author

    By Kubernetes client , you mean the one compiled?

  3. bacongobbler commented on Mar 11, 2022

    @bacongobbler
    Member

    Yes.

  4. ebuildy commented on Mar 11, 2022

    @ebuildy
    Author

    ok I see, to sum up: helm template function .Capabilities.APIVersions.has is not reliable when using argoCD .

    Related to argoproj/argo-cd#3640

    Thanks you, I am continuing on this side.

  5. Morriz commented on Apr 2, 2022

    @Morriz

    Hi, is there any documentation on how to make helm template --kube-version='1.22' --api-versions='networking.k8s.io/v1/Ingress ...' actually use those api-versions without needing any cluster context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions