Version: v1.8

Data Passing

This section introduces how to use Inputs and Outputs to pass data between workflow steps in KubeVela.

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. Use value 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.
  2. Use CUE expressions, eg. use + to combine value and string: valueFrom: output.metadata.name + "testString" or you can import built-in packages in CUE like:
  1. valueFrom: |
  2. import "strings"
  3. strings.Join(["1","2"], ",")

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.

Data Passing - 图1caution

If you want to set the parameterKey with a invalid CUE variable name (eg: contains -, or starts with a number, etc.), you can refer to it with [] like:

  1. inputs:
  2. - from: output
  3. parameterKey: data["my-input"]

eg. Specify inputs:

  1. ...
  2. - name: notify
  3. type: notification
  4. inputs:
  5. - from: read-status
  6. parameterKey: slack.message.text

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:

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: input-output
  5. namespace: default
  6. spec:
  7. components:
  8. - name: express-server
  9. type: webservice
  10. properties:
  11. image: oamdev/hello-world
  12. ports:
  13. - port: 8000
  14. workflow:
  15. steps:
  16. - name: read
  17. type: read-object
  18. properties:
  19. name: depends
  20. outputs:
  21. - name: read-status
  22. valueFrom: output.value.status.workflow.message
  23. - name: slack-message
  24. type: notification
  25. inputs:
  26. - from: read-status
  27. parameterKey: slack.message.text
  28. properties:
  29. slack:
  30. url:
  31. 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.

Last updated on May 6, 2023 by Tianxin Dong