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

1/18/2022

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.

-- Biru
argo-workflows
kubectl
kubernetes

1 Answer

1/18/2022

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
-- crenshaw-dev
Source: StackOverflow