how to pass conditional argument as command in kubernetes with helm charts

Viewed 1425

I have to run a command when my pod start in kubernetes which takes some argument but those argument are conditional. How to set those values. My configuration looks like

#file: values.yaml
arguments:
  debug: false
  values: 16 # this is not necessarily set
#deployment command section looks like
command: [ "/bin/bash", "-ce", "./my_app.sh" ]
args:
    - {{ -f .Values.arguments.debug }}
    - {{ -v .Values.arguments.values}}

But it seems to not accepting argument. Is this incorrect way. How can I pass multiple argument?

1 Answers

Helm uses the Go text/template language with a number of extensions; the Helm Chart Template Guide has quite a few examples.

In particular the templating language includes an if...else...end construct. You can use this like:

args:
  - -f
  - {{ quote .Values.arguments.debug }}
{{- if .Values.arguments.values }}
  - -v
  - {{ quote .Values.arguments.values}}
{{- end }}

Note that the -f and -v text are outside the template curly braces, and I've split them out into separate items in the argument list. In the last part there's a test if the values option is set, and the -v option isn't emitted if it's not.

Related