I have this definition in my values.yaml which is supplied to job.yaml
command: ["/bin/bash"]
args: ["-c", "cd /opt/nonrtric/ric-common/ansible/; cat group_vars/all"]
However, after the pod initializes, I get this error:
/bin/bash: - : invalid option
If i try this syntax:
command: ["/bin/sh", "-c"]
args:
- >
cd /opt/nonrtric/ric-common/ansible/ &&
cat group_vars/all
I get this error: Error: failed to start container "ric-register-avro": Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "/bin/sh -c": stat /bin/sh -c: no such file or directory: unknown
Both sh and bash are supplied in the image, which is CentOS 7
job.yaml
---
apiVersion: batch/v1
kind: Job
metadata:
name: ric-register-avro
spec:
backoffLimit: 0
template:
spec:
containers:
- image: "{{ .Values.ric_register_avro_job.image }}"
name: "{{ .Values.ric_register_avro_job.name }}"
command: {{ .Values.ric_register_avro_job.containers.command }}
args: {{ .Values.ric_register_avro_job.containers.args }}
volumeMounts:
- name: all-file
mountPath: "/opt/nonrtric/ric-common/ansible/group_vars/"
readOnly: true
subPath: all
volumes:
- name: all-file
configMap:
name: ric-register-avro--configmap
restartPolicy: Never
values.yaml
global:
name: ric-register-avro
namespace: foo-bar
ric_register_avro_job:
name: ric-register-avro
all_file:
rest_api_url: http://10.230.227.13/foo
auth_username: foo
auth_password: bar
backoffLimit: 0
completions: 1
image: 10.0.0.1:5000/5gc/ric-app
containers:
name: ric-register-avro
command: ["/bin/bash"]
args: ["-c cd /opt/nonrtric/ric-common/ansible/; cat group_vars/all"]
restartPolicy: Never
2
Answers
I use this:
Trying this simple job I’ve no issue:
In your Helm chart, you directly specify
command:
andargs:
using template syntaxHowever, the output of a
{{ ... }}
block is always a string. If the value you have inside the template is some other type, like a list, it will be converted to a string using some default Go rules, which aren’t especially useful in a Kubernetes context.Helm includes two lightly-documented conversion functions
toJson
andtoYaml
that can help here. Valid JSON is also valid YAML, so one easy approach is just to convert both parts to JSONor, if you want it to look a little more like normal YAML,
or, for that matter, if you’re passing a complete container description via Helm values, it could be enough to
In all of these cases, I’ve put the templating construct starting at the first column, but then used the
indent
function to correctly indent the YAML block. Double-check the indentation and adjust theindent
parameter.You can also double-check that what’s coming out looks correct using
helm template
, using the same-f
option(s) as when you install the chart.(In practice, I might put many of the options you show directly into the chart template, rather than making them configurable as values. The container name, for example, doesn’t need to be configurable, and I’d usually fix the command. For this very specific example you can also set the container’s
workingDir:
rather than runningcd
inside a shell wrapper.)