0

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 the JOB_COMPLETION_INDEX
  • $cnt is the spec.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.

iamacarpet
  • 417
  • 5
  • 13
  • Unfortunately, I think you are going to be stuck having to use the Kubernetes API from within a container to actually do this: https://kubernetes.io/docs/tasks/run-application/access-api-from-pod/#accessing-the-api-from-within-a-pod – Gari Singh Feb 02 '23 at 18:44

0 Answers0