Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ebuildy opened this issue Mar 11, 2022 · 5 comments
Closed

Comments

@ebuildy
Copy link

ebuildy commented Mar 11, 2022

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)

@bacongobbler
Copy link
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.

@ebuildy
Copy link
Author

ebuildy commented Mar 11, 2022

By Kubernetes client , you mean the one compiled?

@bacongobbler
Copy link
Member

Yes.

@ebuildy
Copy link
Author

ebuildy commented Mar 11, 2022

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.

@Morriz
Copy link

Morriz commented Apr 2, 2022

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?

tarrow added a commit to wmde/wbaas-deploy that referenced this issue Feb 26, 2024
This patch hints to helm the capabilities to make the templating
behave properly[1] when using .Capabilities.APIVersions.Has in
charts.

[1] - helm/helm#10760

Bug: T358468
tarrow added a commit to wmde/wbaas-deploy that referenced this issue Feb 26, 2024
)

This patch hints to helm the capabilities to make the templating
behave properly[1] when using .Capabilities.APIVersions.Has in
charts.

[1] - helm/helm#10760

Bug: T358468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants