The yaml below injects the pod's name into the container as RUN_ID. If this cron job spins up 10 pods (parallelism = 10), each of the 10 pods will have a different run id. But I want all the 10 pods to have the same run id. DownwardApi doesn't seem to support retrieving the job id. Is there any other way to do it?
In my case it is not necessary that it needs to be the job id. Any random id that could be set in all 10 pods when a new job is spin up will do. So any ideas for that will also help.
apiVersion: batch/v1
kind: CronJob
metadata:
name: ${CRONJOB_NAME}
namespace: ${NAMESPACE_NAME}
spec:
schedule: "0 8 * * *"
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
backoffLimit: 4
parallelism: ${PARALLEL_JOBS_COUNT}
completions: ${PARALLEL_JOBS_COUNT}
template:
spec:
containers:
- name: ${CONTAINER_NAME}
image: ${DOCKER_IMAGE_NAME}
imagePullPolicy: IfNotPresent
env:
- name: RUN_ID
valueFrom:
fieldRef:
fieldPath: metadata.name ---> this gets the pod's name
.
.
I did RUN_ID=${POD_NAME%\-*}
in a command to extract the job name from the pod name. This solved my use case.
spec:
containers:
- name: ${CONTAINER_NAME}
image: ${ACR_DNS}/${JMETER_DOCKER_IMAGE}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- 'export RUN_ID=${POD_NAME%\-*}; cd /config; /entrypoint.sh -n -Jserver.rmi.ssl.disable=true -Ljmeter.engine=debug -Jjmeterengine.force.system.exit=true -t \$(JMETER_JMX_FILE)'
env:
- name: RUN_ID
valueFrom:
fieldRef:
fieldPath: metadata.name