We've got a CronJob that is utilising Indexed Jobs1 for processing orders in parallel based on a modulus, i.e.
// Skip this order if it doesn't match our thread
if ($threaded && ($d['id'] % $mod) != $cnt) continue;
where:
$mod
is theJOB_COMPLETION_INDEX
$cnt
is thespec.completions
value (total number of completions)spec.completions == spec.parallelism
I've worked with pulling in pod / deployment metadata into environment variables like this before:
containers:
- env:
- name: GKE_SERVICE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.labels['app']
- name: GKE_REVISION
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
And setting spec.completionMode = Indexed
already sets the environment variable JOB_COMPLETION_INDEX
with the exeuction index, but I also need the spec.completions
value.
Is there a way to put spec.completions
into an environment variable without doing it manually?
We'd like to have it pull from the spec to avoid the possibility for mistakes, if the completions count is modified.