Search code examples
kubernetesdeploymentdevopskubernetes-helm

Deploy conditional charts based on kubeVersion - Helm


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


Solution

  • 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.