'How to get the argo workflow age in seconds using kubectl command

Is there a way to fetch a specific argo workflow age in seconds using kubectl command?

I've a requirement for comparing the argo workflow age. If the workflow age is greater than 24 hours I need to terminate the workflow.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1