步骤超时

步骤超时 - 图1备注

你需要升级到 1.5 及以上版本来使用超时功能。

本节将介绍如何在 KubeVela 中为工作流步骤添加超时时间。

在 KubeVela 工作流中,每个步骤都可以指定一个 timeout,你可以使用 timeout 来指定该步骤的超时时间。

timeout 遵循 duration 格式,例如 30s, 1m 等。你可以参考 Golang 的 parseDuration

如果一个步骤在指定的时间内没有完成,KubeVela 会将该步骤的状态置为 failed,步骤的 Reason 会设置为 timeout

部署如下例子:

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: timeout-example
  5. namespace: default
  6. spec:
  7. components:
  8. - name: comp1
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. - name: comp2
  14. type: webservice
  15. properties:
  16. image: crccheck/hello-world
  17. port: 8000
  18. workflow:
  19. steps:
  20. - name: apply-comp1
  21. type: apply-component
  22. properties:
  23. component: comp1
  24. - name: suspend
  25. type: suspend
  26. timeout: 5s
  27. - name: apply-comp2
  28. type: apply-component
  29. properties:
  30. component: comp2

使用 vela status 命令查看应用状态:

  1. $ vela status timeout-example
  2. About:
  3. Name: timeout-example
  4. Namespace: default
  5. Created at: 2022-06-25 00:51:43 +0800 CST
  6. Status: workflowTerminated
  7. Workflow:
  8. mode: StepByStep
  9. finished: true
  10. Suspend: false
  11. Terminated: true
  12. Steps
  13. - id:1f58n13qdp
  14. name:apply-comp1
  15. type:apply-component
  16. phase:succeeded
  17. message:
  18. - id:1pfije4ugt
  19. name:suspend
  20. type:suspend
  21. phase:failed
  22. message:
  23. - id:lqxyenjxj4
  24. name:apply-comp2
  25. type:apply-component
  26. phase:skipped
  27. message:
  28. Services:
  29. - Name: comp1
  30. Cluster: local Namespace: default
  31. Type: webservice
  32. Healthy Ready:1/1
  33. No trait applied

可以看到,当第一个组件被成功部署后,工作流会暂停在第二个 suspend 步骤上。该 suspend 步骤被设置了一个五秒的超时时间,如果在五秒内没有继续该工作流的话,该步骤会因为超时而失败。而第三个步骤因为前面的 suspend 步骤失败了,从而被跳过了执行。