暂停和继续
本节将介绍如何在 KubeVela 中暂停和继续工作流。
暂停工作流
在 KubeVela 中,你可以选择使用 vela 命令来手动暂停工作流的执行,也可以使用一个内置的特殊步骤类型 suspend 使工作流自动进入暂停状态。
手动暂停
如果你有一个正在运行的应用,并且你希望暂停它的执行,你可以使用 vela workflow suspend 来暂停该工作流。
$ vela workflow suspend my-appSuccessfully suspend workflow: my-app
使用暂停步骤
部署如下例子:
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: suspendnamespace: defaultspec:components:- name: comp1type: webserviceproperties:image: crccheck/hello-worldport: 8000- name: comp2type: webserviceproperties:image: crccheck/hello-worldport: 8000workflow:steps:- name: apply1type: apply-componentproperties:component: comp1- name: suspendtype: suspend- name: apply2type: apply-componentproperties:component: comp2
使用 vela status 命令查看应用状态:
$ vela status suspendAbout:Name: suspendNamespace: defaultCreated at: 2022-06-27 17:36:58 +0800 CSTStatus: workflowSuspendingWorkflow:mode: StepByStepfinished: falseSuspend: trueTerminated: falseSteps- id:yj9h29uv6vname:apply1type:apply-componentphase:succeededmessage:- id:xvmda4he5ename:suspendtype:suspendphase:runningmessage:Services:- Name: comp1Cluster: local Namespace: defaultType: webserviceHealthy Ready:1/1No trait applied
可以看到,当第一个步骤执行完成之后,会开始执行 suspend 步骤。而这个步骤会让工作流进入暂停状态。
继续工作流
手动继续工作流
当工作流进入暂停状态后,你可以使用 vela workflow resume 命令来手动继续工作流。workflow resume 命令会把工作流从暂停状态恢复到执行状态。
以上面处于暂停状态的应用为例:
$ vela workflow resume suspendSuccessfully resume workflow: suspend
成功继续工作流后,查看应用的状态:
$ vela status suspendAbout:Name: suspendNamespace: defaultCreated at: 2022-06-27 17:36:58 +0800 CSTStatus: runningWorkflow:mode: StepByStepfinished: trueSuspend: falseTerminated: falseSteps- id:yj9h29uv6vname:apply1type:apply-componentphase:succeededmessage:- id:xvmda4he5ename:suspendtype:suspendphase:succeededmessage:- id:66jonaxjefname:apply2type:apply-componentphase:succeededmessage:Services:- Name: comp2Cluster: local Namespace: defaultType: webserviceHealthy Ready:1/1No trait applied- Name: comp1Cluster: local Namespace: defaultType: webserviceHealthy Ready:1/1No trait applied
可以看到,工作流已经继续执行完毕。
手动终止工作流
当工作流处于暂停状态时,如果你想终止它,你可以使用 vela workflow terminate 命令来终止工作流。
$ vela workflow terminate my-appSuccessfully terminate workflow: my-app
自动继续工作流
如果你希望经过了一段时间后,工作流能够自动被继续。那么,你可以在 suspend 步骤中加上 duration 参数。当 duration 时间超过后,工作流将自动继续执行。
部署如下例子:
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: auto-resumenamespace: defaultspec:components:- name: comp1type: webserviceproperties:image: crccheck/hello-worldport: 8000- name: comp2type: webserviceproperties:image: crccheck/hello-worldport: 8000workflow:steps:- name: apply1type: apply-componentproperties:component: comp1- name: suspendtype: suspendproperties:duration: 5s- name: apply2type: apply-componentproperties:component: comp2
查看应用状态:
$ vela status auto-resumeAbout:Name: auto-resumeNamespace: defaultCreated at: 2022-06-27 17:57:35 +0800 CSTStatus: runningWorkflow:mode: StepByStepfinished: trueSuspend: falseTerminated: falseSteps- id:q5jhm6mgwvname:apply1type:apply-componentphase:succeededmessage:- id:3xgfcp3cujname:suspendtype:suspendphase:succeededmessage:- id:zjux8ud876name:apply2type:apply-componentphase:succeededmessage:Services:- Name: comp2Cluster: local Namespace: defaultType: webserviceHealthy Ready:1/1No trait applied- Name: comp1Cluster: local Namespace: defaultType: webserviceHealthy Ready:1/1No trait applied
可以看到,suspend 步骤在五秒后自动执行成功,继续了工作流。