Merge pull request #774 from FogDong/feat-1.4-wf

Feat: add new workflow docs
This commit is contained in:
Tianxin Dong 2022-06-28 17:47:09 +08:00 committed by GitHub
commit c8bb46060f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1826 additions and 4 deletions

View File

@ -0,0 +1,105 @@
---
title: Dependency
---
This section will introduce how to specify dependencies for workflow steps.
> Note: In the current version (1.4), the steps in the workflow are executed sequentially, which means that there is an implicit dependency between steps, ie: the next step depends on the successful execution of the previous step. At this point, specifying dependencies in the workflow may not make much sense.
>
> In future versions (1.5+), you will be able to display the execution method of the specified workflow steps (eg: change to DAG parallel execution). At this time, you can control the execution of the workflow by specifying the dependencies of the steps.
## How to use
In KubeVela, the dependencies between steps can be specified by `dependsOn` in the steps.
For example: we want to send a message notification after deploying the component:
```yaml
...
workflow:
steps:
- name: comp
type: apply-component
- name: notify
type: notification
dependsOn:
- comp
```
In this case, KubeVela waits for the completion of the step `comp` before executing the `notify` step to send a message notification.
Apply the following YAML:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: dependsOn-app
namespace: default
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
workflow:
steps:
- name: comp
type: apply-component
properties:
component: express-server
- name: slack-message
type: notification
dependsOn:
- comp
properties:
slack:
url:
value: <your slack url>
message:
text: depends on comp
```
## Expected outcome
Use `vela status` to check the status of the Application:
```bash
$ vela status depends
About:
Name: depends
Namespace: default
Created at: 2022-06-24 17:20:50 +0800 CST
Status: running
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: false
Steps
- id:e6votsntq3
name:comp
type:apply-component
phase:succeeded
message:
- id:esvzxehgwc
name:slack-message
type:notification
phase:succeeded
message:
Services:
- Name: express-server
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
As you can see, all step statuses are succeeded. And when the component is successfully deployed, a message is also sent in slack.

View File

@ -0,0 +1,274 @@
---
title: If conditions
---
This section introduces how to add if conditions to workflow steps.
In the KubeVela workflow, each step can specify an `if`, in which you can determine whether the step should be executed.
## No If specified
In the case where a step does not specify an If, KubeVela will determine whether to execute the step based on the status of the previous steps. In default, if all the previous steps are succeeded, the step will be executed.
This also means that if step A fails, step B after step A will be skipped and will not be executed.
Apply the following example:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: err-with-no-if
namespace: default
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
workflow:
steps:
- name: apply-err
type: apply-object
properties:
value:
test: err
- name: apply-comp
type: apply-component
properties:
component: express-server
```
Use `vela status` to check the status of the Application:
```bash
$ vela status err-with-no-if
About:
Name: err-with-no-if
Namespace: default
Created at: 2022-06-24 18:14:46 +0800 CST
Status: workflowTerminated
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: true
Steps
- id:bztlmifsjl
name:apply-err
type:apply-object
phase:failed
message:step apply: run step(provider=kube,do=apply): Object 'Kind' is missing in '{"test":"err"}'
- id:el8quwh8jh
name:apply-comp
type:apply-component
phase:skipped
message:
Services:
```
As you can see, the step `apply-err` will fail due to an attempt to deploy an invalid resource, and the step `apply-comp` will be skipped because the previous step failed.
## If Always
If you want a step to be executed anyway, you can specify `if` to `always` for this step.
Apply the following example:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: err-with-always
namespace: default
spec:
components:
- name: invalid
type: webservice
properties:
image: invalid
ports:
- port: 8000
workflow:
steps:
- name: comp
type: apply-component
timeout: 5s
outputs:
- name: status
valueFrom: output.status.conditions[0].type + output.status.conditions[0].status
properties:
component: invalid
- name: notification
type: notification
inputs:
- from: status
parameterKey: slack.message.text
if: always
properties:
slack:
url:
value: <your slack url>
```
Use `vela status` to check the status of the Application:
```bash
$ vela status err-with-always
About:
Name: err-with-always
Namespace: default
Created at: 2022-06-27 17:30:29 +0800 CST
Status: workflowTerminated
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: true
Steps
- id:loeqr6dlcn
name:comp
type:apply-component
phase:failed
message:
- id:hul9tayu82
name:notification
type:notification
phase:succeeded
message:
Services:
- Name: invalid
Cluster: local Namespace: default
Type: webservice
Unhealthy Ready:0/1
No trait applied
```
You can see that step `comp` will try to deploy a component whose image is `invalid`, and the component will fail due to timeout after five seconds because the image cannot be pulled. In the meanwhile, this step passes the component's `status` as outputs. The step `notification` will be executed because `if: always` is specified. At the same time, the content of the message notification is the status of the component in the previous step. Therefore, we can see the message notification carrying the status information in slack.
## Custom If conditions
> Note: You need to upgrade to version 1.5 or above to use custom If conditions.
You can also write your own judgment logic to determine whether the step should be executed. Note: The value in `if` will be executed as CUE codes. KubeVela provides some built-in variables in `if`, they are:
* `status``status` contains status information for all workflow steps. You can use `status.<step-name>.phase == "succeeded"` to determine the status of a step, or you can use the simplified `status.<step-name>.succeeded` to determine.
* `inputs``inputs` contains all the inputs parameters of the step. You can use `inputs.<input-name> == "value"` to get input for the step.
> Note that if your step name or inputs name is not a valid CUE variable name (eg: contains `-`, or starts with a number, etc.), you can refer to it as follows: `status["invalid-name"].failed`
Apply the following example:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: custom-if
namespace: default
spec:
components:
- name: comp-custom-if
type: webservice
properties:
image: crccheck/hello-world
port: 8000
traits:
workflow:
steps:
- name: apply
type: apply-component
properties:
component: comp-custom-if
outputs:
- name: comp-output
valueFrom: context.name
- name: notification
type: notification
inputs:
- from: comp-output
parameterKey: slack.message.text
if: inputs["comp-output"] == "custom-if"
properties:
slack:
url:
value: <your slack url>
- name: notification-skip
type: notification
if: status.notification.failed
properties:
slack:
url:
value: <your slack url>
message:
text: this notification should be skipped
- name: notification-succeeded
type: notification
if: status.notification.succeeded
properties:
slack:
url:
value: <your slack url>
message:
text: the notification is succeeded
```
Use `vela status` to check the status of the Application:
```bash
$ vela status custom-if
About:
Name: custom-if
Namespace: default
Created at: 2022-06-25 00:37:14 +0800 CST
Status: running
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: false
Steps
- id:un1zd8qc6h
name:apply
type:apply-component
phase:succeeded
message:
- id:n5xbtgsi68
name:notification
type:notification
phase:succeeded
message:
- id:2ufd3v6n78
name:notification-skip
type:notification
phase:skipped
message:
- id:h644x6o8mb
name:notification-succeeded
type:notification
phase:succeeded
message:
Services:
- Name: comp-custom-if
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
As you can see, after the first step `apply` succeeded, the outputs `comp-output` will be output. The second step `notification` refers to the outputs of the first step as inputs and makes a judgment. After the condition is met, the notification is successfully sent. The third step `notification-skip` judges whether the second step is in a failed state. If the condition is not met, this step is skipped. The fourth step `notification-succeeded` judges whether the second step is successful, if the condition is met, the step is successfully executed.

View File

@ -0,0 +1,74 @@
---
title: Pass data between steps
---
This section introduces how to use `Inputs` and `Outputs` to pass data between workflow steps in KubeVela.
## Outputs
Outputs consists of `name` and `valueFrom`. `name` declares the name of this output, which will be referenced by `from` in input.
`valueFrom` can be written in the following ways:
1. Fill string value in the field, eg. `valueFrom: "testString"`.
2. Use CUE expression, eg. `valueFrom: output.value.status.workflow.message`. Note that `output.value.status.workflow.message` will use the value of the variable from the CUE template of the current step. If this field does not exist in the CUE template of the step, the resulting value will be empty.
3. Use `+` to combine above two ways, the computed value will be the result, eg. `valueFrom: output.value.status.workflow.message + "testString"`.
## Inputs
Inputs is made of `from` and `parameterKey`. Input uses `from` to reference output, `parameterKey` is a expression that assigns the value of the input to the corresponding field.
eg. Specify inputs:
```yaml
...
- name: notify
type: notification
inputs:
- from: read-status
parameterKey: slack.message.text
```
## How to use
Suppose we already have a `depends` application in the cluster, and we want to read the workflow status of the `depends` Application in a new Application and send the status information to Slack.
Apply the following YAML:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: input-output
namespace: default
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
workflow:
steps:
- name: read
type: read-object
properties:
name: depends
outputs:
- name: read-status
valueFrom: output.value.status.workflow.message
- name: slack-message
type: notification
inputs:
- from: read-status
parameterKey: slack.message.text
properties:
slack:
url:
value: <your slack url>
```
> When reading the `depends` application, we use the `read-object` step type. In this step type, the read resources will be placed in `output.value`, so we can use `output.value.status.workflow.message` reads the workflow status information of `depends`.
When the application runs successfully, we can receive the workflow status information of the `depends` application in the Slack message notification.

View File

@ -0,0 +1,52 @@
---
title: Workflow Overview
---
## Overview
Workflows, as part of the Application, can glue together additional delivery processes and specify arbitrary delivery environments. In short, `Workflow` provides customized control flow and flexibility based on the original delivery model of Kubernetes(Apply). For example, `Workflow` can be used to implement complex operations such as pause, manual approval, if conditions, waiting status, data flow, multi-environment gray release, A/B testing, etc.
A workflow consists of multiple steps, and typical workflow steps include step groups (containing a series of sub-steps), human review, multi-cluster publishing, notifications, etc. You can view all built-in workflow steps provided by default in KubeVela in [built-in workflow steps](./built-in-workflow-defs). If the built-in workflow steps don't meet your needs, you can also [custom workflow steps](../../platform-engineers/workflow/workflow).
`Workflow` consists of steps, you can either use KubeVela's [built-in workflow steps](./built-in-workflow-defs) like `suspend`, `notification`, `deploy`, `step-group` etc, or [customize your own `WorkflowStepDefinition`](../../platform-engineers/workflow/workflow).
In fact, if you only use components in the Application and do not declare a workflow, KubeVela will automatically create a default workflow for deploying the components when running the Application.
In VelaUX, you can feel the workflow more intuitively. As shown in the figure: The following is a workflow that controls the application to be deployed to the test environment, paused in the manual approval step, and then deployed to the production environment:
![continue-workflow](../../resources/continue-workflow.png)
## Execution order
In the workflow, all the steps will be executed sequentially and the next step will be executed after the previous one succeeded. If a step is of type `step-group`, it can contain a series of sub-steps, all of which are executed together when the step group is executed.
> In future versions of KubeVela (1.5+), you can explicitly specify the execution mode of steps, such as:
> ```yaml
> workflow:
> mode:
> steps: StepByStep
> subSteps: DAG
> ```
> There're two modes of execution: StepByStep and DAG.
>
> If you do not explicitly declare the execution mode, by default steps are executed sequentially in StepByStep and subSteps are executed in parallel in DAG.
## State of Application and Workflow
| Application | Workflow | Description |
| :-------: | :----: | :-----------------------------------: |
| runningWorkflow | executing | When the workflow is executing, the status of the application is runningWorkflow |
| workflowSuspending | suspending | When the workflow is suspended, the status of the application is workflowSuspending |
| workflowTerminated | terminated | When a step in the workflow fails or is terminated, the status of the application is workflowTerminated |
| running | succeeded | When all steps in the workflow are executed successfully, the status of the application is running |
## Core features
Workflow has powerful process control capabilities, including:
- View [Suspend and Resume Workflow](./suspend) to learn how to suspend and resume a workflow.
- View [Sub Steps](./step-group) to learn how to use sub-steps in the workflow.
- View [Dependency](./dependency) to learn how to specify dependencies for workflow steps.
- View [Pass data between steps](./inputs-outputs) to learn how to use `inputs`, `outputs` to pass data between steps.
- View [If Conditions](./if-condition) to learn how to use `if` to determine whether the step should be executed.
- View [Timeout Steps](./timeout) to learn how to set `timeout` for steps.

View File

@ -0,0 +1,54 @@
---
title: Step Group
---
This section describes how to use sub steps in KubeVela.
There is a special step type `step-group` in KubeVela workflow where you can declare sub-steps when using `step-group` type steps.
> Note: In the current version (1.4), sub steps in a step group are executed concurrently.
>
> In future versions (1.5+), you will be able to specify the execution mode of steps and sub-steps.
Apply the following example:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: sub-success
spec:
components:
- name: express-server1
type: webservice
properties:
image: crccheck/hello-world
- name: express-server2
type: webservice
properties:
image: crccheck/hello-world
- name: express-server3
type: webservice
properties:
image: crccheck/hello-world
workflow:
steps:
- name: step1
type: apply-component
properties:
component: express-server1
- name: step2
type: step-group
subSteps:
- name: step2-sub1
type: apply-component
properties:
component: express-server2
- name: step2-sub2
type: apply-component
properties:
component: express-server3
```
By default, steps are executed sequentially, so step2 is not executed until step1 is deployed. Whereas in the step-group, sub-steps will be executed concurrently by default, so step2-sub1 and step2-sub2 will be deployed at the same time.

View File

@ -0,0 +1,258 @@
---
title: Suspend and Resume Workflow
---
This section introduces how to suspend and resume the workflow in KubeVela.
## Suspend the Workflow
In KubeVela, you can choose to use the `vela` command to manually suspend the execution of the workflow, or use a built-in special step type `suspend` to automatically suspend the workflow.
### Suspend Manually
If you have a running application and you want to suspend its execution, you can use `vela workflow suspend` to suspend the workflow.
```bash
$ vela workflow suspend my-app
Successfully suspend workflow: my-app
```
### Use Suspend Step
Apply the following example:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: suspend
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
```
Use `vela status` to check the status of the Application:
```bash
$ vela status suspend
About:
Name: suspend
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
message:
- id:xvmda4he5e
name:suspend
type:suspend
phase:running
message:
Services:
- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
As you can see, when the first step is completed, the `suspend` step will be executed and this step will suspend the workflow.
## Resume the Workflow
### Resume Manually
Once the workflow is suspended, you can use the `vela workflow resume` command to manually resume the workflow.
Take the above suspended application as an example:
```bash
$ vela workflow resume suspend
Successfully resume workflow: suspend
```
After successfully continuing the workflow, view the status of the app:
```bash
$ vela status suspend
About:
Name: suspend
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
```
As you can see, the workflow has continued to execute.
### Terminate Manually
If you want to terminate a workflow while it is suspended, you can use the `vela workflow terminate` command to terminate the workflow.
```bash
$ vela workflow terminate my-app
Successfully terminate workflow: my-app
```
### Resume the Workflow Automatically
If you want the workflow to be continued automatically after a period of time has passed. Then, you can add a `duration` parameter to the `suspend` step. When the `duration` time elapses, the workflow will automatically continue execution.
Apply the following example:
```yaml
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
```
Use `vela status` to check the status of the Application:
```bash
$ 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
```
As you can see, the `suspend` step is automatically executed successfully after five seconds, and the workflow is executed successfully.

View File

@ -0,0 +1,93 @@
---
title: Timeout Steps
---
> Note: You need to upgrade to version 1.5 or above to use the timeout.
This section introduces how to add timeout to workflow steps in KubeVela.
In KubeVela workflow, each step can specify a `timeout`, you can use `timeout` to specify the timeout time for the step.
`timeout` follows the `duration` format, e.g. `30s`, `1m`, etc. You can refer to Golang's [parseDuration](https://pkg.go.dev/time#ParseDuration).
If a step is not completed within the specified time, KubeVela will set the status of the step to `failed` and the `Reason` of the step will be set to `Timeout`.
Apply the following example:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: timeout-example
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: apply-comp1
type: apply-component
properties:
component: comp1
- name: suspend
type: suspend
timeout: 5s
- name: apply-comp2
type: apply-component
properties:
component: comp2
```
Use `vela status` to check the status of the Application:
```bash
$ vela status timeout-example
About:
Name: timeout-example
Namespace: default
Created at: 2022-06-25 00:51:43 +0800 CST
Status: workflowTerminated
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: true
Steps
- id:1f58n13qdp
name:apply-comp1
type:apply-component
phase:succeeded
message:
- id:1pfije4ugt
name:suspend
type:suspend
phase:failed
message:
- id:lqxyenjxj4
name:apply-comp2
type:apply-component
phase:skipped
message:
Services:
- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
As you can see, when the first component is successfully deployed, the workflow is suspended on the second `suspend` step. The `suspend` step is set with a timeout of five seconds. If the workflow is not resumed within five seconds, the step will fail because of timeout. The third step is skipped because the previous `suspend` step failed.

View File

@ -112,7 +112,7 @@ mysql mysql-secret raw running healthy 2021-10-14 12:09:55 +0
### Outputs
outputs 由 `name``valueFrom` 组成。`name` 声明了这个 output 的名称,在 input 中将通过 `name` 引用 output。
outputs 由 `name``valueFrom` 组成。`name` 声明了这个 output 的名称,在 input 中将通过 `from` 引用 output。
`valueFrom` 有以下几种写法:
1. 直接通过字符串表示值,如:`valueFrom: testString`。

View File

@ -0,0 +1,105 @@
---
title: 依赖关系
---
本节将介绍如何在 KubeVela 中指定工作流步骤的依赖关系。
> 注意在当前版本1.4)中,工作流中的步骤是顺序执行的,这意味着步骤间有一个隐式的依赖关系,即:下一个步骤依赖上一个步骤的成功执行。此时,在工作流中指定依赖关系的意义可能不大。
>
> 在未来的版本1.5+)中,你将可以显示指定工作流步骤的执行方式(如:改成 DAG 并行执行),此时,你可以通过指定步骤的依赖关系来控制工作流的执行。
## 如何使用
在 KubeVela 中,可以在步骤中通过 `dependsOn` 来指定步骤间的依赖关系。
如:我们希望在部署完组件之后,发送一个消息通知:
```yaml
...
workflow:
steps:
- name: comp
type: apply-component
- name: notify
type: notification
dependsOn:
- comp
```
在这种情况下KubeVela 等待步骤 comp 执行完毕后,再执行 notify 步骤发送消息通知。
部署如下 YAML
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: dependsOn-app
namespace: default
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
workflow:
steps:
- name: comp
type: apply-component
properties:
component: express-server
- name: slack-message
type: notification
dependsOn:
- comp
properties:
slack:
url:
value: <your slack url>
message:
text: depends on comp
```
## 期望结果
使用 vela status 命令查看应用的状态:
```bash
$ vela status depends
About:
Name: depends
Namespace: default
Created at: 2022-06-24 17:20:50 +0800 CST
Status: running
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: false
Steps
- id:e6votsntq3
name:comp
type:apply-component
phase:succeeded
message:
- id:esvzxehgwc
name:slack-message
type:notification
phase:succeeded
message:
Services:
- Name: express-server
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
可以看到所有的步骤状态均为成功。并且当组件被成功部署后slack 中也收到了一条消息通知。

View File

@ -0,0 +1,274 @@
---
title: 条件判断
---
本节将介绍如何在 KubeVela 中为工作流步骤添加条件判断。
在 KubeVela 工作流中,每个步骤都可以指定一个 `if`,你可以使用 `if` 来确定是否应该执行该步骤。
## 不指定 If
在步骤没有指定 If 的情况下KubeVela 会根据先前步骤的状态来判断是否应该执行该步骤。默认步骤的执行条件是:在该步骤前的所有步骤状态均为成功。
这也意味着,如果步骤 A 执行失败,那么步骤 A 之后的步骤 B 会被跳过,不会被执行。
部署如下例子:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: err-with-no-if
namespace: default
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
workflow:
steps:
- name: apply-err
type: apply-object
properties:
value:
test: err
- name: apply-comp
type: apply-component
properties:
component: express-server
```
使用 vela status 命令查看应用状态:
```bash
$ vela status err-with-no-if
About:
Name: err-with-no-if
Namespace: default
Created at: 2022-06-24 18:14:46 +0800 CST
Status: workflowTerminated
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: true
Steps
- id:bztlmifsjl
name:apply-err
type:apply-object
phase:failed
message:step apply: run step(provider=kube,do=apply): Object 'Kind' is missing in '{"test":"err"}'
- id:el8quwh8jh
name:apply-comp
type:apply-component
phase:skipped
message:
Services:
```
可以看到,步骤 `apply-err` 会因为尝试部署一个非法的资源而导致失败,同时,因为之前的步骤失败了,步骤 `apply-comp` 将被跳过。
## If Always
如果你希望一个步骤无论如何都应该被执行,那么,你可以为这个步骤指定 `if``always`
部署如下例子:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: err-with-always
namespace: default
spec:
components:
- name: invalid
type: webservice
properties:
image: invalid
ports:
- port: 8000
workflow:
steps:
- name: comp
type: apply-component
timeout: 5s
outputs:
- name: status
valueFrom: output.status.conditions[0].type + output.status.conditions[0].status
properties:
component: invalid
- name: notification
type: notification
inputs:
- from: status
parameterKey: slack.message.text
if: always
properties:
slack:
url:
value: <your slack url>
```
使用 vela status 命令查看应用状态:
```bash
$ vela status err-with-always
About:
Name: err-with-always
Namespace: default
Created at: 2022-06-27 17:30:29 +0800 CST
Status: workflowTerminated
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: true
Steps
- id:loeqr6dlcn
name:comp
type:apply-component
phase:failed
message:
- id:hul9tayu82
name:notification
type:notification
phase:succeeded
message:
Services:
- Name: invalid
Cluster: local Namespace: default
Type: webservice
Unhealthy Ready:0/1
No trait applied
```
可以看到,步骤 `comp` 会去尝试部署一个镜像为 `invalid` 的组件,而组件因为拉取不到镜像,所以会在五秒后因为超时而失败,同时,这个步骤将组件的 `status` 作为 outputs 传出。而步骤 `notification` 因为指定了 `if: always`,所以一定会被执行,同时,消息通知的内容为上一个步骤中组件的状态,因此,我们可以在 slack 中看到携带状态信息的消息通知。
## 自定义 If 条件判断
> 注意:你需要升级到 1.5 及以上版本来使用自定义 If 条件判断。
你也可以编写自己的判断逻辑来确定是否应该执行该步骤。注意: `if` 里的值将作为 CUE 代码执行。KubeVela 在 `if` 中提供了一些内置变量,它们是:
* `status`status 中包含了所有工作流步骤的状态信息。你可以使用 `status.<step-name>.phase == "succeeded"` 来判断步骤的状态,也可以使用简化方式`status.<step-name>.succeeded` 来进行判断。
* `inputs`inputs 中包含了该步骤的所有 inputs 参数。你可以使用 `inputs.<input-name> == "value"` 来获取判断步骤的输入。
> 注意,如果你的步骤名或者 inputs 名并不是一个有效的 CUE 变量名(如:包含 `-`,或者以数字开头等),你可以用如下方式引用:`status["invalid-name"].failed`
部署如下例子:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: custom-if
namespace: default
spec:
components:
- name: comp-custom-if
type: webservice
properties:
image: crccheck/hello-world
port: 8000
traits:
workflow:
steps:
- name: apply
type: apply-component
properties:
component: comp-custom-if
outputs:
- name: comp-output
valueFrom: context.name
- name: notification
type: notification
inputs:
- from: comp-output
parameterKey: slack.message.text
if: inputs["comp-output"] == "custom-if"
properties:
slack:
url:
value: <your slack url>
- name: notification-skip
type: notification
if: status.notification.failed
properties:
slack:
url:
value: <your slack url>
message:
text: this notification should be skipped
- name: notification-succeeded
type: notification
if: status.notification.succeeded
properties:
slack:
url:
value: <your slack url>
message:
text: the notification is succeeded
```
使用 vela status 命令查看应用状态:
```bash
$ vela status custom-if
About:
Name: custom-if
Namespace: default
Created at: 2022-06-25 00:37:14 +0800 CST
Status: running
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: false
Steps
- id:un1zd8qc6h
name:apply
type:apply-component
phase:succeeded
message:
- id:n5xbtgsi68
name:notification
type:notification
phase:succeeded
message:
- id:2ufd3v6n78
name:notification-skip
type:notification
phase:skipped
message:
- id:h644x6o8mb
name:notification-succeeded
type:notification
phase:succeeded
message:
Services:
- Name: comp-custom-if
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
可以看到,第一个步骤 `apply` 成功后,会输出一个 outputs。第二个步骤 `notification` 中引用第一个步骤的 outputs 作为 inputs 并且进行判断,满足条件后成功发送通知。第三个步骤 `notification-skip` 判断第二个步骤是否为失败状态,条件不满足,这个步骤跳过。第四个步骤 `notification-succeeded` 判断第二个步骤是否成功,条件满足,该步骤成功执行。

View File

@ -0,0 +1,74 @@
---
title: 数据传递
---
本节将介绍如何在 KubeVela 中使用 Inputs 和 Outputs 在工作流步骤间进行数据传递。
## Outputs
outputs 由 `name``valueFrom` 组成。`name` 声明了这个 output 的名称,在 input 中将通过 `from` 引用 output。
`valueFrom` 有以下几种写法:
1. 直接通过字符串表示值,如:`valueFrom: "testString"`。
2. 通过 CUE 表达式来指定值,如:`valueFrom: output.value.status.workflow.message`。注意,`output.value.status.workflow.message` 将使用变量引用的方式从当前步骤的 CUE 模板中取值,如果该步骤的 CUE 模板中没有该字段,那么得到的值为空。
3. 通过 `+` 来任意连接以上两种写法,最终值是计算后的字符串拼接结果,如:`valueFrom: output.value.status.workflow.message + "testString"`。
## Inputs
inputs 由 `from``parameterKey` 组成。`from` 声明了这个 input 从哪个 output 中取值,`parameterKey` 为一个表达式,将会把 input 取得的值赋给对应的字段。
如:
1. 指定 inputs:
```yaml
...
- name: notify
type: notification
inputs:
- from: read-status
parameterKey: slack.message.text
```
## 如何使用
假设我们已经在集群中有了一个 depends 应用,我们希望在一个新的应用中读取到 depends 应用的工作流状态,并且发送状态信息到 Slack 中。
部署如下应用:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: input-output
namespace: default
spec:
components:
- name: express-server
type: webservice
properties:
image: oamdev/hello-world
ports:
- port: 8000
workflow:
steps:
- name: read
type: read-object
properties:
name: depends
outputs:
- name: read-status
valueFrom: output.value.status.workflow.message
- name: slack-message
type: notification
inputs:
- from: read-status
parameterKey: slack.message.text
properties:
slack:
url:
value: <your slack url>
```
> 读取 depends 应用时,我们使用了 `read-object` 这个步骤类型,在这个步骤类型中,读取到的资源会被放在 `output.value` 中,因此,我们可以使用 `output.value.status.workflow.message` 读取到 depends 应用的工作流状态信息。
当应用成功运行后,我们可以在 Slack 消息通知中收到 `depends` 应用的工作流状态信息。

View File

@ -0,0 +1,50 @@
---
title: 工作流总览
---
## 总览
工作流作为一个应用部署计划的一部分,可以帮助你自定义应用部署计划中的步骤,粘合额外的交付流程,指定任意的交付环境。简而言之,工作流提供了定制化的控制逻辑,在原有 Kubernetes 模式交付资源Apply的基础上提供了面向过程的灵活性。比如说使用工作流实现条件判断、暂停、状态等待、数据流传递、多环境灰度、A/B 测试等复杂操作。
工作流由多个步骤组成,典型的工作流步骤包括步骤组(包含一系列子步骤)、人工审核、多集群发布、通知等。你可以在 [内置工作流步骤](./built-in-workflow-defs) 中查看 KubeVela 默认提供的所有内置工作流步骤。如果内置的工作流步骤无法满足你的需求,你也可以 [自定义工作流步骤](../../platform-engineers/workflow/workflow)。
实际上如果你在应用部署计划中只使用了组件并没有声明工作流时KubeVela 会在运行这个应用时自动创建一个默认的工作流,用于部署应用中的组件。
在 VelaUX 中,你可以更加直观地感受工作流。如图:下面是一个控制应用先部署到测试环境,暂停在人工审核步骤,然后再部署到生产环境的工作流:
![continue-workflow](../../resources/continue-workflow.png)
## 执行顺序
在工作流中,所有的步骤将顺序执行,下一个步骤将在上一个步骤成功后执行。如果一个步骤的类型为步骤组,那么它可以包含一系列子步骤,在执行这个步骤组时,所有子步骤都会一起执行。
> 在 KubeVela 未来的版本1.5+)中,你可以显示地指定步骤的执行方式来控制并发或者单步执行,如:
> ```yaml
> workflow:
> mode:
> steps: StepByStep
> subSteps: DAG
> ```
> 执行方式有两种StepByStep 顺序执行以及 DAG 并行执行。
>
> steps 中可以指定步骤的执行方式subSteps 指定步骤组中子步骤的执行方式。如果你不显示声明执行模式,默认 steps 以 StepByStep 顺序执行subSteps 以 DAG 并行执行。
## 工作流与应用的状态对应
| 应用 | 工作流 | 说明 |
| :-------: | :----: | :-----------------------------------: |
| runningWorkflow | executing | 当工作流正在执行时,应用的状态为 runningWorkflow |
| workflowSuspending | suspending | 当工作流暂停时,应用的状态为 workflowSuspending |
| workflowTerminated | terminated | 当工作流中有步骤失败或者被终止时,应用的状态为 workflowTerminated |
| running | succeeded | 当工作流中所有步骤都成功执行后,应用的状态为 running |
## 核心功能
工作流拥有丰富的流程控制能力,包括:
- 查看 [暂停和继续工作流](./suspend),了解如何在工作流中使用暂停步骤完成人工审核,自动继续等功能。
- 查看 [子步骤](./step-group),了解如何在工作流中使用子步骤完成一组步骤的执行。
- 查看 [依赖关系](./dependency),了解如何指定工作流步骤间的依赖关系。
- 查看 [数据传递](./inputs-outputs),了解如何通过 `inputs`、`outputs` 来进行步骤间的数据传递。
- 查看 [使用条件判断](./if-condition),了解如何使用条件判断来控制工作流步骤的执行。
- 查看 [步骤的超时](./timeout),了解如何指定工作流步骤的超时时间。

View File

@ -0,0 +1,54 @@
---
title: 子步骤
---
本节将介绍如何在 KubeVela 中使用子步骤。
KubeVela 工作流中有一个特殊的步骤类型 `step-group`,在使用步骤组类型的步骤时,你可以在其中声明子步骤。
> 注意在当前版本1.4)中,步骤组中的子步骤们是并发执行的。
>
> 在未来的版本1.5+)中,你将可以显示指定工作流步骤及子步骤的执行方式。
部署如下例子:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: sub-success
spec:
components:
- name: express-server1
type: webservice
properties:
image: crccheck/hello-world
- name: express-server2
type: webservice
properties:
image: crccheck/hello-world
- name: express-server3
type: webservice
properties:
image: crccheck/hello-world
workflow:
steps:
- name: step1
type: apply-component
properties:
component: express-server1
- name: step2
type: step-group
subSteps:
- name: step2-sub1
type: apply-component
properties:
component: express-server2
- name: step2-sub2
type: apply-component
properties:
component: express-server3
```
在默认情况下步骤顺序执行因此step1 部署完成后才会执行 step2。而在步骤组中默认子步骤将并发执行因此 step2-sub1 和 step2-sub2 将同时部署。

View File

@ -0,0 +1,258 @@
---
title: 暂停和继续工作流
---
本节将介绍如何在 KubeVela 中暂停和继续工作流。
## 暂停工作流
在 KubeVela 中,你可以选择使用 `vela` 命令来手动暂停工作流的执行,也可以使用一个内置的特殊步骤类型 `suspend` 使工作流自动进入暂停状态。
### 手动暂停
如果你有一个正在运行的应用,并且你希望暂停它的执行,你可以使用 `vela workflow suspend` 来暂停该工作流。
```bash
$ vela workflow suspend my-app
Successfully suspend workflow: my-app
```
### 使用暂停步骤
部署如下例子:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: suspend
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 命令查看应用状态:
```bash
$ vela status suspend
About:
Name: suspend
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
message:
- id:xvmda4he5e
name:suspend
type:suspend
phase:running
message:
Services:
- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
可以看到,当第一个步骤执行完成之后,会开始执行 `suspend` 步骤。而这个步骤会让工作流进入暂停状态。
## 继续工作流
### 手动继续工作流
当工作流进入暂停状态后,你可以使用 `vela workflow resume` 命令来手动继续工作流。workflow resume 命令会把工作流从暂停状态恢复到执行状态。
以上面处于暂停状态的应用为例:
```bash
$ vela workflow resume suspend
Successfully resume workflow: suspend
```
成功继续工作流后,查看应用的状态:
```bash
$ vela status suspend
About:
Name: suspend
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
```
可以看到,工作流已经继续执行完毕。
### 手动终止工作流
当工作流处于暂停状态时,如果你想终止它,你可以使用 `vela workflow terminate` 命令来终止工作流。
```bash
$ vela workflow terminate my-app
Successfully terminate workflow: my-app
```
### 自动继续工作流
如果你希望经过了一段时间后,工作流能够自动被继续。那么,你可以在 `suspend` 步骤中加上 `duration` 参数。当 `duration` 时间超过后,工作流将自动继续执行。
部署如下例子:
```yaml
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
```
查看应用状态:
```bash
$ 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` 步骤在五秒后自动执行成功,继续了工作流。

View File

@ -0,0 +1,93 @@
---
title: 步骤的超时
---
> 注意:你需要升级到 1.5 及以上版本来使用超时功能。
本节将介绍如何在 KubeVela 中为工作流步骤添加超时时间。
在 KubeVela 工作流中,每个步骤都可以指定一个 `timeout`,你可以使用 `timeout` 来指定该步骤的超时时间。
`timeout` 遵循 `duration` 格式,例如 `30s`, `1m` 等。你可以参考 Golang 的 [parseDuration](https://pkg.go.dev/time#ParseDuration)。
如果一个步骤在指定的时间内没有完成KubeVela 会将该步骤的状态置为 `failed`,步骤的 Reason 会设置为 `timeout`
部署如下例子:
```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: timeout-example
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: apply-comp1
type: apply-component
properties:
component: comp1
- name: suspend
type: suspend
timeout: 5s
- name: apply-comp2
type: apply-component
properties:
component: comp2
```
使用 vela status 命令查看应用状态:
```bash
$ vela status timeout-example
About:
Name: timeout-example
Namespace: default
Created at: 2022-06-25 00:51:43 +0800 CST
Status: workflowTerminated
Workflow:
mode: StepByStep
finished: true
Suspend: false
Terminated: true
Steps
- id:1f58n13qdp
name:apply-comp1
type:apply-component
phase:succeeded
message:
- id:1pfije4ugt
name:suspend
type:suspend
phase:failed
message:
- id:lqxyenjxj4
name:apply-comp2
type:apply-component
phase:skipped
message:
Services:
- Name: comp1
Cluster: local Namespace: default
Type: webservice
Healthy Ready:1/1
No trait applied
```
可以看到,当第一个组件被成功部署后,工作流会暂停在第二个 `suspend` 步骤上。该 `suspend` 步骤被设置了一个五秒的超时时间,如果在五秒内没有继续该工作流的话,该步骤会因为超时而失败。而第三个步骤因为前面的 `suspend` 步骤失败了,从而被跳过了执行。

View File

@ -87,9 +87,13 @@ module.exports = {
label: 'Declarative Workflow',
collapsed: true,
items: [
'tutorials/workflows',
'end-user/workflow/component-dependency-parameter',
'end-user/workflow/webhook-notification',
'end-user/workflow/overview',
'end-user/workflow/suspend',
'end-user/workflow/step-group',
'end-user/workflow/dependency',
'end-user/workflow/inputs-outputs',
'end-user/workflow/if-condition',
'end-user/workflow/timeout',
],
},
{