maxisme
maxisme

Reputation: 4265

How to uniquely identify a cronjob run from within the pod

I currently have a kubernetes CronJob with a concurrencyPolicy: Forbid. I would like to be able to uniquely identify this pod externally (k8 cluster) and internally from the pod, with an ID that will be unique forever. I was thinking of using the creationTimestamp and the name of the pod but unfortunately it is not that easy to pass the creationTimestamp. Any other ideas?

Upvotes: 1

Views: 602

Answers (1)

ericfossas
ericfossas

Reputation: 2196

Just use the pod name like you had figured out from your other question:

- name: POD_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name

The pod name should be very unique (if you want completely unique, you'll need to grab its UID, but i'm not sure what you're trying to solve).

The pod name will be generated using the following format:

{{CRONJOB_NAME}}-{{UNIX_TIMESTAMP_IN_MINUTES}}-{{5_CHAR_RANDOM_ALPHANUM}}

Upvotes: 3

Related Questions