I am using the Helm chart for Apache Airflow and creating a user using the createUserJob
section:
airflow:
createUserJob:
command: ~
args:
- "bash"
- "-c"
- |-
exec \
airflow {{ semverCompare ">=2.0.0" .Values.airflowVersion | ternary "users create" "create_user" }} "$@"
- --
- "-r"
- "{{ .Values.webserver.defaultUser.role }}"
- "-u"
- "{{ .Values.webserver.defaultUser.username }}"
- "-e"
- "{{ .Values.webserver.defaultUser.email }}"
- "-f"
- "{{ .Values.webserver.defaultUser.firstName }}"
- "-l"
- "{{ .Values.webserver.defaultUser.lastName }}"
- "-p"
- "{{ .Values.webserver.defaultUser.password }}"
However, if it exists, I would like to delete the user before creating it, but the following does not work:
airflow:
createUserJob:
command: ~
args:
- "bash"
- "-c"
- |-
exec \
airflow users delete --username admin ;
airflow {{ semverCompare ">=2.0.0" .Values.airflowVersion | ternary "users create" "create_user" }} "$@"
- --
- "-r"
- "{{ .Values.webserver.defaultUser.role }}"
- "-u"
- "{{ .Values.webserver.defaultUser.username }}"
- "-e"
- "{{ .Values.webserver.defaultUser.email }}"
- "-f"
- "{{ .Values.webserver.defaultUser.firstName }}"
- "-l"
- "{{ .Values.webserver.defaultUser.lastName }}"
- "-p"
- "{{ .Values.webserver.defaultUser.password }}"
Is there a way to run more than one command here?
CodePudding user response:
Remove the word exec
.
The syntax you show here runs bash -c 'command' args
as the main container command, where args
is a list of arguments that are expanded inside the command as $0
, $1
, $2
, and so on. Inside the command string "$@"
expands to those positional parameters starting at $1
. This is set up correctly.
Inside the command string, exec
is a special built-in utility: exec some_command
replaces the current shell with some_command
, and in effect ends the current script. In a container context this is useful for controlling which process is the main container process, but in this short-lived script it's not especially necessary. In particular if you're going to exec
a command it must be the last command.
I might structure this as:
command:
- /bin/sh
- -c
- |-
airflow users delete --username "{{ .Values.webserver.defaultUser.username }}";
airflow users create "$@"
# (no `exec` in this command string)
- --
args:
- "-r"
- "{{ .Values.webserver.defaultUser.role }}"
- "-et"
- cetera
Here the command:
/args:
split is kind of artificial but it makes it slightly clearer how the command words are split up.