Tekton:如何删除成功的管道?

发布于 2025-02-12 16:33:50 字数 734 浏览 0 评论 0原文

我急剧的Tekton Usecase很简单:

  • X天失败后,应删除成功的管道弹药,
  • 因此不应自动删除Pipelineruns。

我计划在最初的清理任务中进行清理。在我看来,这比注释或cronjob诉求更好。只要没有任何新的建造,就无需删除。

直接方法:

  • 失败TKN DELETE似乎并没有很有帮助,因为它不会区分成功与否。
  • 失败oc delete-field-selector ...不包含隐藏良好但高度表达的字段状态。条件[0] .type ====成功的

间接方法(首先过滤podnames的列表,然后删除它们 - 根本不是优雅):

  • 失败 :用-O = JSONPATH过滤输出...似乎代价高昂,条件 - 阵列似乎打破了声明,所以(为什么曾经呢?!)一切都返回...
  • 我的最后一次尝试是tkn Pipelineruns列表-Show-show maregand-fields和用sed/awk来解析这一点……这很粗糙……但是至少它可以做我想做的事情……而且非常有效。但是,当输出的设计将在未来的版本中变化时,可能会导致脆弱...

您有更好的优雅方法吗? 多谢!

My aspired tekton usecase is simple:

  • successful pipelineruns should be removed after x days
  • failed pipelineruns shouldn't be removed automatically.

I plan to do the cleanup in an initial cleanup-task. That seems better to me than annotation- or cronjob-approaches. As long as nothing new is built, nothing has to be deleted.

Direct approaches:

  • Failed: tkn delete doesn't seem very helpful because it doesn't discriminate between successful or not.
  • Failed: oc delete --field-selector ... doesn't contain the well hidden but highly expressive field status.conditions[0].type==Succeeded

Indirect approaches (first filtering a list of podnames and then delete them - not elegant at all):

  • Failed: Filtering output with -o=jsonpath... seems costly and the condition-array seems to break the statement, so that (why ever?!) everything is returned... not viable
  • My last attempt is tkn pipelineruns list --show-managed-fields and parse this with sed/awk... which is gross... but at least it does what I want it to do... and quite efficiently at that. But it might result as brittle when the design of the output is going to change in future releases...

Do you have any better more elegant approaches?
Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甚是思念 2025-02-19 16:33:50

在有更好的解决方案之前,我将发布我当前的解决方案(及其缺点):

我们的清理任务现在围绕以下解决方案构建,评估由tkn Pipelineruns list列表>:

tkn pipelineruns list --show-managed-fields -n e-dodo-tmgr --label tekton.dev/pipeline=deploy-pipeline | awk '$6~/Succeeded/ && $3~/day|week|month/ {print $1}'

优势:

  • 如果没有广泛的呼叫或其他计算,它应该做什么。

缺点:

  • 时间仅限于“超过一个小时 /每天 /一周的年龄段”……但是这是可以接受的,因为只有成功的构建。
  • 我猜该设计非常脆弱,因为随着TKN-CLIENT的变化,表格的格式可能会更改,这意味着AWK会选择错误的列或类似的模式合并。

总而言之,我希望该解决方案能够保留,直到有更多有用的客户端功能使所需信息可以直接过滤。实际上,我希望tkn Pipelineruns删除 - State成功-Period P1D
该时间段的符号来自ISO8601。

Until a better solution is there, I'll post my current solution (and its drawbacks):

Our cleanup-task is now built around the following solution, evaluating the table returned by tkn pipelineruns list:

tkn pipelineruns list --show-managed-fields -n e-dodo-tmgr --label tekton.dev/pipeline=deploy-pipeline | awk '$6~/Succeeded/ && $3~/day|week|month/ {print $1}'

Advantages:

  • It does what it should without extensive calls or additional calculation.

Disadvantages:

  • Time is limited to "older than an hour / a day / a week ..." But that's acceptable, since only successful builds are concerned.
  • I guess the design is quite brittle, because with changes in the tkn-Client the format of the table might change which implies that awk will pick the wrong columns, or similar pattern-probs.

All in all I hope the solution will hold until there are some more helpful client-features that make the desired info directly filterable. Actually I'd hope for something like tkn pipelineruns delete --state successful --period P1D.
The notation for the time period is from ISO8601.

孤独陪着我 2025-02-19 16:33:50

为了完整,我在这里粘贴了kubectl/oc本机命令,为我们这些没有TKN CLI的人。根据需要替换target-namespace

删除失败的管道:

kubectl -n target-namespace delete pipelinerun $(kubectl -n target-namespace get pipelinerun -o jsonpath='{range .items[?(@.status.conditions[*].status=="False")]}{.metadata.name}{"\n"}{end}')

删除成功的Pipelineruns:

kubectl -n target-namespace delete pipelinerun $(kubectl -n target-namespace get pipelinerun -o jsonpath='{range .items[?(@.status.conditions[*].status=="True")]}{.metadata.name}{"\n"}{end}')

For completeness, I paste here the kubectl/oc native command for those of us who do not have the tkn cli. Replace target-namespace as needed.

Delete failed pipelineruns:

kubectl -n target-namespace delete pipelinerun $(kubectl -n target-namespace get pipelinerun -o jsonpath='{range .items[?(@.status.conditions[*].status=="False")]}{.metadata.name}{"\n"}{end}')

Delete successful pipelineruns:

kubectl -n target-namespace delete pipelinerun $(kubectl -n target-namespace get pipelinerun -o jsonpath='{range .items[?(@.status.conditions[*].status=="True")]}{.metadata.name}{"\n"}{end}')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文