I have two env vars in a pod (or a config map):
- TARGET_URL=http://www.example.com
- TARGET_PARAM=param
Is there any way for me to provide a third env var which is derived from both these vars, something like ${TARGET_URL}/mysite/${TARGET_PARAM}
.
Thanks!
You can do using an init script that you can call at docker entry point.
I don't think it is possible right now, without a 3rd party tool. regarding api ref it does not support multi variable in YAML. But I will tell you about a 3rd party tool -- Helm
It is possible to achieve it using Helm. your template will look like:
containers:
- name: {{.Values.Backend.name }}
image: "{{ .Values.Backend.image.repository }}:{{ .Values.Backend.image.tag }}"
imagePullPolicy: "{{ .Values.Backend.image.pullPolicy }}"
args:
- name: TARGET_URL
value: {{ .Value.URL}}
- name: TARGET_PARAM
value: {{ .Value.PARAM}}
- name: URL
value: {{ .Value.URL }}/mysite/{{ .Value.PARAM}}
and you will add to the file values.yaml
parameters for TARGET_URL
and TARGET_PARAM
URL: http://www.example.com
PARAM: param
For environment variables (and a couple of other fields in the pod spec, including args
and command
) there is a Make-like $(VARIABLE)
name that will get expanded; see for example the documentation for .env.value
. This could look like:
env:
- name: TARGET_URL
valueFrom:
configMapKeyRef:
key: cm
name: TARGET_URL
- name: TARGET_PARAM
valueFrom:
configMapKeyRef:
key: cm
name: TARGET_PARAM
- name: TARGET_DETAIL_URL
value: $(TARGET_URL)/mysite/$(TARGET_PARAM)
If you are depending on mounting a ConfigMap into a container as files, then it can only contain static content; this trick won't work.