Formatting dates in Argo

3.4k views Asked by At

In order to get a date like 20201008 in Argo, what's the best way of formatting a date in a template?

This seems to work but is fairly verbose, and creating the string for something like "%Y-%m-%dT%H:%M:%SZ" is going to get very difficult for others to read.

 "{{workflow.creationTimestamp.Y}}{{workflow.creationTimestamp.m}}{{workflow.creationTimestamp.d}}"

I think these are the relevant docs: https://github.com/argoproj/argo/blob/master/docs/variables.md. I tried "{{workflow.creationTimestamp.Ymd}}" but no luck.

2

There are 2 answers

0
Maximilian On BEST ANSWER

Since Argo 3.1, some templating is supported, such that this now works:

"{{=sprig.date('20060102', workflow.creationTimestamp)}}"
1
crenshaw-dev On

Unfortunately, there is no way (inside of the template) to make this more concise.

There is a hard-coded list of supported time format characters. For each character in that list, a global parameter is populated, along with the base workflow.creationTimestamp variable. There is no dynamic reading or processing of the characters after workflow.creationTimestamp..

Since the templating is based on Jinja2, there has been discussion of more robust string templating support. But various complications have stalled that discussion. (The Argo team uses "thumbs up" counts to prioritize issues, so it might help to give that issue a bump.)

I'm sure you've thought of this, but for the sake of completeness: if you are using the variable in a pod you could send the full workflow.creationTimestamp and do some runtime manipulation to get the format you want.

Finally, you can submit an issue to request the feature. Even if they decide not to implement it, the example would make the discussion about Jinja2 templating a bit more concrete for the developers.