I have a cronjob that should process events occurred since the last operation, for that I use DB to persist this timestamp, my question is whether or not it is possible to directly pass Kubernetes status.lastScheduleTime into the cronjob object as an environment variable?
I see the easiest way accomplish your goal via kubectl set env
command, injecting into the particular Cronjob template object the desired status.lastScheduleTime
field as environment variable LAST_SCHEDULE
:
kubectl set env cronjob/name LAST_SCHEDULE=$(kubectl get cronjob name -o jsonpath='{.status.lastScheduleTime}')
env:
- name: LAST_SCHEDULE
value: "2019-09-23T08:56:00Z"
You may also find a more comprehensive way achieving Cronjob
resource patching, supplying target environment variable in the corresponded template with most recent lastScheduleTime
value via Init Containers or through postStart
/preStop
handlers.