简体   繁体   English

如何使用 kubectl 命令以秒为单位获取 argo 工作流年龄

[英]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?有没有办法使用kubectl命令在几秒钟内获取特定的 argo 工作流年龄?

I've a requirement for comparing the argo workflow age.我需要比较 argo 工作流程的年龄。 If the workflow age is greater than 24 hours I need to terminate the workflow.如果工作流年龄大于 24 小时,我需要终止工作流。

You should probably use Argo Workflow's built-in, declarative timeout feature :您可能应该使用Argo Workflow 的内置声明式超时功能

spec:
  activeDeadlineSeconds: 86400

That will fail the workflow if it takes over 24 hours.如果需要超过 24 小时,这将使工作流程失败。 To actually delete the workflow, set a TTL policy .要实际删除工作流,请设置TTL 策略

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:我永远无法抗拒一个好的jq挑战,所以这里有一个基于脚本的替代方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM