Version: v1.3

Step Operations

This documentation will introduce the CUE operations provided in vela/op stdlib package that can be used in each workflow step.

To learn the syntax of CUE, read CUE Basic


Create or update resource in Kubernetes cluster.

  • value: the resource structure to be created or updated. And after successful execution, value will be updated with resource status.
  • patch: the content support Strategic Merge Patch,let you can define the strategy of list merge through comments.
  1. #Apply: {
  2. value: {...}
  3. patch: {
  4. //patchKey=$key
  5. ...
  6. }
  7. }
  1. import "vela/op"
  2. stepName: op.#Apply & {
  3. value: {
  4. kind: "Deployment"
  5. apiVersion: "apps/v1"
  6. metadata: name: "test-app"
  7. spec: {
  8. replicas: 2
  9. ...
  10. }
  11. }
  12. patch: {
  13. spec: template: spec: {
  14. //patchKey=name
  15. containers: [{name: "sidecar"}]
  16. }
  17. }
  18. }

Step will be blocked until the condition is met.

  • continue: Step will be blocked until the value becomes true.
  1. #ConditionalWait: {
  2. continue: bool
  3. }
  1. import "vela/op"
  2. apply: op.#Apply
  3. wait: op.#ConditionalWait: {
  4. continue: apply.value.status.phase=="running"
  5. }

Get all components in application.

No parameters.

  1. #Load: {}
  1. import "vela/op"
  2. // You can use `load.value.[componentName] after this action.
  3. load: op.#Load & {}

Get resource in Kubernetes cluster.

  • value: the resource metadata to be get. And after successful execution, value will be updated with resource definition in cluster.
  • err: if an error occurs, the err will contain the error message.
  1. #Read: {
  2. value: {}
  3. err?: string
  4. }
  1. // You can use configmap.value.data after this action.
  2. configmap: op.#Read & {
  3. value: {
  4. kind: "ConfigMap"
  5. apiVersion: "v1"
  6. metadata: {
  7. name: "configmap-name"
  8. namespace: "configmap-ns"
  9. }
  10. }
  11. }

Create or update resources corresponding to the application in Kubernetes cluster.

No parameters.

  1. #ApplyApplication: {}
  1. apply: op.#ApplyApplication & {}

Create or update resources corresponding to the component in Kubernetes cluster. Note that need to use Load first to apply the resources.

  • value: the load value of the resource.
  • patch: the value to patch resource.
  1. #ApplyComponent: {
  2. value: {...}
  3. patch: {...}
  4. }
  1. load: op.#Load & {}
  2. apply: op.#ApplyComponent & {
  3. value: load.value[parameter.component]
  4. }

Create or update the resources corresponding to all components in the application in the Kubernetes cluster, and specify which components do not need to apply through exceptions, or skip some resources of the exceptional component.

  • exceptions: indicates the name of the exceptional component.
  1. #ApplyRemaining: {
  2. exceptions?: [...string]
  3. }
  1. apply: op.#ApplyRemaining & {
  2. exceptions: ["applied-component-name"]
  3. }

Send messages to Slack.

  • url: The webhook address of Slack.
  • message: The messages that you want to send, please refer to Slack messaging
  1. #Slack: {
  2. url: string
  3. message: {...}
  4. }
  1. apply: op.#Slack & {
  2. url: webhook url
  3. message:
  4. text: Hello KubeVela
  5. }

Send messages to DingTalk.

  • url: The webhook address of DingTalk.
  • message: The messages that you want to send, please refer to DingTalk messaging
  1. #DingTalk: {
  2. url: string
  3. message: {...}
  4. }
  1. apply: op.#DingTalk & {
  2. url: webhook url
  3. message:
  4. msgtype: text
  5. text:
  6. context: Hello KubeVela
  7. }

Used to encapsulate a set of operations.

  • In steps, you need to specify the execution order by tag.
  1. app: op.#Steps & {
  2. load: op.#Load & {
  3. component: "component-name"
  4. } @step(1)
  5. apply: op.#Apply & {
  6. value: load.value.workload
  7. } @step(2)
  8. }

used to save or read user-defined data in the context of workflow

  • method: The value is get or put, which indicates whether the action reads or saves data from workflow
  • path: Path to save or read data
  • value: Data content (in the format of cue). When the method is get, it indicates the read data, otherwise it indicates the data to be saved
  1. put: op.ws.#DoVar & {
  2. method: "Put"
  3. path: "foo.score"
  4. value: 100
  5. }
  6. // The user can get the data saved above through get.value (100)
  7. get: op.ws.#DoVar & {
  8. method: "Get"
  9. path: "foo.score"
  10. }

Last updated on Nov 1, 2022 by Tianxin Dong