1

we are defining a initContainer for our helm chart. relevant part is the following

  initContainers:
      - name: "set-volumes-init"
        image: "IMAGE AND TAG"
        command: ['sh', '-c', 'COMMAND 1 && COMMAND 2 && COMMAND 3']
        volumeMounts:
        - name: volume-summary
          mountPath: /usr/summ

the question is: how do i make the "command" like have the different commands according to if a value is defined or not?

e.g: if i have the value: podx.val2 defined, i want the COMMAND 2 to be included, but if its not, then i dont want it.

same for other COMMANDS

2
  • What have you already tried? Have you read The (Helm) Chart Template Developer’s Guide? Commented Oct 3, 2018 at 0:57
  • I tried adding multiple "command" annotation, but i kept getting the error "key 'command' is duplicated". in the end, since that command is bash, i added some pipes to make the commands work even if they cant find the required directory Commented Oct 3, 2018 at 13:31

1 Answer 1

1

If I were doing this, I'd build a custom image that contained the shell script, and have it controlled by environment variables.

#!/bin/sh
if [ -n "$DO_COMMAND_2" ]; then
  command2
fi

The style you've written could work with a combination of YAML block syntax and Helm conditionals. This is probably harder to maintain and test, but something like this should work:

command: >-
  command1
{{ if .Values.val2 }}
  && command2
{{ end }}
  && command3

The YAML >- syntax will cause everything indented after it to get folded into a single line, which helps the whitespace-control issues.

Sign up to request clarification or add additional context in comments.

1 Comment

what does define the "end" of the resulting folded lane?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.