Home > Software engineering >  Deploy conditional charts based on kubeVersion - Helm
Deploy conditional charts based on kubeVersion - Helm

Time:12-17

I have two helm charts with versions : 1.3 & 4.0. I'm looking for ways to deploy charts in CI CD process, based on cluster kubeVerion, if kubeVersion > 1.19 then v4.0 else v1.3. How can I achieve this type of conditional option in Charts.yaml, is there any way for this?

Thanks in advance.

Update: Helm v3 in use

CodePudding user response:

The helm charts are not "logic" defining elements. They are just artifacts or a piece of "blob" which can exist in one version or the other (e.g. one for 1.3 and one for 4.0).

It should be up to your CI/CD system and pipeline logic to check the Kubernetes version and then download and deploy the right chart/blob/file.

A blob or a file its-self won't be able to decide on logics, that's what a helm chart is eventually

CodePudding user response:

Yes, it is possible since Helm has some built-in objects.

I think you are probably looking for .Capabilities.KubeVersion.Minor.

You just need to put an if at the top of your template, then if the version doesn't match, Helm won't deploy it.

eg:

{{- if ge .Capabilities.KubeVersion.Minor 19 }}
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
   name: "{{ app_v4 }}"
...
...
{{- end }}

If you have both templates in the same file, you can use else to improve the logic. Template Functions and Pipelines.

  • Related