Skip to main content
版本:v1.8

暂停和继续

本节将介绍如何在 KubeVela 中暂停和继续工作流。

暂停工作流

在 KubeVela 中,你可以选择使用 vela 命令来手动暂停工作流的执行,也可以使用一个内置的特殊步骤类型 suspend 使工作流自动进入暂停状态。

手动暂停

如果你有一个正在运行工作流的应用,并且你希望暂停它的执行,你可以使用 vela workflow suspend 来暂停该工作流,在未来可以通过 vela workflow resume 继续工作流。

  • 暂停工作流
vela workflow suspend my-app
提示

如果工作流已经执行完毕,对应用使用 vela workflow suspend 命令不会产生任何效果。

使用暂停步骤

部署如下例子:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: suspend-demo
namespace: default
spec:
components:
- name: comp1
type: webservice
properties:
image: crccheck/hello-world
port: 8000
- name: comp2
type: webservice
properties:
image: crccheck/hello-world
port: 8000
workflow:
steps:
- name: apply1
type: apply-component
properties:
component: comp1
- name: suspend
type: suspend
- name: apply2
type: apply-component
properties:
component: comp2

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

vela status suspend-demo
期望输出
About:

Name: suspend-demo
Namespace: default
Created at: 2022-06-27 17:36:58 +0800 CST
Status: workflowSuspending

Workflow:

mode: StepByStep
finished: false
Suspend: true
Terminated: false
Steps
- id:yj9h29uv6v
name:apply1
type:apply-component
phase:succeeded
- id:xvmda4he5e
name:suspend
type:suspend
phase:running

Services:

- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied

可以看到,当第一个步骤执行完成之后,会开始执行 suspend 步骤。而这个步骤会让工作流进入暂停状态。

继续工作流

手动继续工作流

当工作流进入暂停状态后,你可以使用 vela workflow resume 命令来手动继续工作流。workflow resume 命令会把工作流从暂停状态恢复到执行状态。

以上面处于暂停状态的应用为例:

vela workflow resume suspend-demo

成功继续工作流后,查看应用的状态:

vela status suspend-demo
期望输出
About:

Name: suspend-demo
Namespace: default
Created at: 2022-06-27 17:36:58 +0800 CST
Status: running

Workflow:

mode: StepByStep
finished: true
Suspend: false
Terminated: false
Steps
- id:yj9h29uv6v
name:apply1
type:apply-component
phase:succeeded
message:
- id:xvmda4he5e
name:suspend
type:suspend
phase:succeeded
message:
- id:66jonaxjef
name:apply2
type:apply-component
phase:succeeded
message:

Services:

- Name: comp2
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied

- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied

可以看到,工作流已经继续执行完毕。

自动继续工作流

如果你希望经过了一段时间后,工作流能够自动被继续。那么,你可以在 suspend 步骤中加上 duration 参数。当 duration 时间超过后,工作流将自动继续执行。

部署如下例子:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: auto-resume
namespace: default
spec:
components:
- name: comp1
type: webservice
properties:
image: crccheck/hello-world
port: 8000
- name: comp2
type: webservice
properties:
image: crccheck/hello-world
port: 8000
workflow:
steps:
- name: apply1
type: apply-component
properties:
component: comp1
- name: suspend
type: suspend
properties:
duration: 5s
- name: apply2
type: apply-component
properties:
component: comp2

查看应用状态:

vela status auto-resume
期望输出
About:

Name: auto-resume
Namespace: default
Created at: 2022-06-27 17:57:35 +0800 CST
Status: running

Workflow:

mode: StepByStep
finished: true
Suspend: false
Terminated: false
Steps
- id:q5jhm6mgwv
name:apply1
type:apply-component
phase:succeeded
message:
- id:3xgfcp3cuj
name:suspend
type:suspend
phase:succeeded
message:
- id:zjux8ud876
name:apply2
type:apply-component
phase:succeeded
message:

Services:

- Name: comp2
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied

- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied

可以看到,suspend 步骤在五秒后自动执行成功,继续了工作流。