Home > Software design >  condition statement in helm chart configmap
condition statement in helm chart configmap

Time:10-10

I have the following configmap-app.yaml file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Chart.Name }}
  labels:
    {{- include "app.labels" . | nindent 4 }}
data:
  application.yaml: {{ (tpl (.Files.Get "files/application.yaml") . | quote ) }}

For application.yaml I need to add one config file or the other, based on a boolean flag:

{{ if .Values.validation.enabled }}
    # use first configmap
{{ else }}
    # use second configmap
{{ end }}

If validation.enabled=true then application.yaml should read from files/application-first.yaml and if validation.enabled=false, then it should read from files/application-second.yaml. How can I accomplish that?

CodePudding user response:

Your example/assumption seems correct, you just need to specify second file in the else section.

{{ if .Values.validation.enabled }}
    application.yaml: {{ (tpl (.Files.Get "files/application.yaml") . | quote ) }}
{{ else }}
    application.yaml: {{ (tpl (.Files.Get "files/application-second.yaml") . | quote ) }}
{{ end }}

Make sure to add a variable in the value file

validation:
  enabled: true
  • Related