Version: v1.1

Data Passing

This section will introduce how to pass data between components.

Inputs and Outputs

In KubeVela, we can use inputs and outputs in Components to pass data.

Outputs

Outputs is made of name and valueFrom. Input will use name to reference output.

We can write valueFrom in the following ways:

  1. Fill string value in the field, eg. valueFrom: testString.
  2. Use expression, eg. valueFrom: output.metadata.name. Note that output is a built-in field referring to the resource in the component that is rendered and deployed to the cluster.
  3. Use + to combine above two ways, the computed value will be the result, eg. valueFrom: output.metadata.name + "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.

  1. Specify inputs:
  1. ...
  2. - name: wordpress
  3. type: helm
  4. inputs:
  5. - from: mysql-svc
  6. parameterKey: properties.values.externalDatabase.host
  1. The field parameterKey specifies the field path of the parameter key in component to be assigned after rendering:

Which means the input value will be passed into the below properties:

  1. ...
  2. - name: wordpress
  3. type: helm
  4. properties:
  5. values:
  6. externalDatabase:
  7. host: <input value>

How to use

In the following we will apply a WordPress server with the MySQL address passed from a MySQL component:

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: wordpress-with-mysql
  5. namespace: default
  6. spec:
  7. components:
  8. - name: mysql
  9. type: helm
  10. outputs:
  11. # the output is the mysql service address
  12. - name: mysql-svc
  13. exportKey: output.metadata.name + ".default.svc.cluster.local"
  14. properties:
  15. repoType: helm
  16. url: https://charts.bitnami.com/bitnami
  17. chart: mysql
  18. version: "8.8.2"
  19. values:
  20. auth:
  21. rootPassword: mypassword
  22. - name: wordpress
  23. type: helm
  24. inputs:
  25. # set the host to mysql service address
  26. - from: mysql-svc
  27. parameterKey: properties.values.externalDatabase.host
  28. properties:
  29. repoType: helm
  30. url: https://charts.bitnami.com/bitnami
  31. chart: wordpress
  32. version: "12.0.3"
  33. values:
  34. mariadb:
  35. enabled: false
  36. externalDatabase:
  37. user: root
  38. password: mypassword
  39. database: mysql
  40. port: 3306

Expected Outcome

The WordPress with MySQL has been successfully applied.