How to get the argo workflow age in seconds using kubectl command
You should probably use Argo Workflow's built-in, declarative timeout feature:
spec:
activeDeadlineSeconds: 86400
That will fail the workflow if it takes over 24 hours. To actually delete the workflow, set a TTL policy.
ttlStrategy:
secondsAfterCompletion: 60
The cost optimizations docs have some other notes which will be helpful when designing your cleanup strategy.
I can never resist a good jq
challenge, so here's a script-based alternative:
WORKFLOW_NAME=something
if kubectl get wf -n argo "$WORKFLOW_NAME" -ojson | jq --exit-status 'now - (.metadata.creationTimestamp | fromdateiso8601) > (24*60*60)'; then
kubectl delete wf -n argo "$WORKFLOW_NAME"
fi