Helm: break loop (range) in template

4/1/2020

I have an application which is hosted on multiple environments and helm chart is used to deploy the application. I have values.yaml-

app:
  component: mobile
  type: web 
  env: prd --> (It will override with external parameters while deployment like dev / stg / uat)


image:
  repository: ********.dkr.ecr.ap-south-1.amazonaws.com/mobile
  pullPolicy: IfNotPresent
  versions:
    v1:
      name: stable
      replicaCount: 2
      tag: latest
    v2:
      name: release
      replicaCount: 1
      tag: latest

Based on version v1 and v2(canary fashion), Deployment will iterate over loop. Canary deployment will be perform only on PRD environment. So on DEV / STG / UAT, only one version will be deployed and therefore loop will needed to iterate only one time for such environment.

{{- range $version, $val := $.Values.image.versions }}
---
apiVersion: apps/v1
kind: Deployment

I can set number of required pods for v2 as 0 but it create unnecessary metadata (deployemnt, replicaset).

So is there any method to break loop in helm template with condition (env: prd) to avoid loop iteration over v2.

-- Ashish Kumar
azure-kubernetes
eks
google-kubernetes-engine
kubernetes
kubernetes-helm

0 Answers