Version: v1.0

Status Write Back

This documentation will explain how to achieve status write back by using CUE templates in definition objects.

Health Check

The spec of health check is spec.status.healthPolicy, they are the same for both Workload Type and Trait.

If not defined, the health result will always be true.

The keyword in CUE is isHealth, the result of CUE expression must be bool type. KubeVela runtime will evaluate the CUE expression periodically until it becomes healthy. Every time the controller will get all the Kubernetes resources and fill them into the context field.

So the context will contain following information:

  1. context:{
  2. name: <component name>
  3. appName: <app name>
  4. output: <K8s workload resource>
  5. outputs: {
  6. <resource1>: <K8s trait resource1>
  7. <resource2>: <K8s trait resource2>
  8. }
  9. }

Trait will not have the context.output, other fields are the same.

The example of health check likes below:

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: ComponentDefinition
  3. spec:
  4. status:
  5. healthPolicy: |
  6. isHealth: (context.output.status.readyReplicas > 0) && (context.output.status.readyReplicas == context.output.status.replicas)
  7. ...
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: TraitDefinition
  3. spec:
  4. status:
  5. healthPolicy: |
  6. isHealth: len(context.outputs.service.spec.clusterIP) > 0
  7. ...

Please refer to this doc for the complete example.

The health check result will be recorded into the Application resource.

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. spec:
  4. components:
  5. - name: myweb
  6. type: worker
  7. properties:
  8. cmd:
  9. - sleep
  10. - "1000"
  11. enemies: alien
  12. image: busybox
  13. lives: "3"
  14. traits:
  15. - type: ingress
  16. properties:
  17. domain: www.example.com
  18. http:
  19. /: 80
  20. status:
  21. ...
  22. services:
  23. - healthy: true
  24. message: "type: busybox,\t enemies:alien"
  25. name: myweb
  26. traits:
  27. - healthy: true
  28. message: 'Visiting URL: www.example.com, IP: 47.111.233.220'
  29. type: ingress
  30. status: running

Custom Status

The spec of custom status is spec.status.customStatus, they are the same for both Workload Type and Trait.

The keyword in CUE is message, the result of CUE expression must be string type.

The custom status has the same mechanism with health check. Application CRD controller will evaluate the CUE expression after the health check succeed.

The context will contain following information:

  1. context:{
  2. name: <component name>
  3. appName: <app name>
  4. output: <K8s workload resource>
  5. outputs: {
  6. <resource1>: <K8s trait resource1>
  7. <resource2>: <K8s trait resource2>
  8. }
  9. }

Trait will not have the context.output, other fields are the same.

Please refer to this doc for the complete example.

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: ComponentDefinition
  3. spec:
  4. status:
  5. customStatus: |-
  6. message: "type: " + context.output.spec.template.spec.containers[0].image + ",\t enemies:" + context.outputs.gameconfig.data.enemies
  7. ...
  1. apiVersion: core.oam.dev/v1beta1
  2. kind: TraitDefinition
  3. spec:
  4. status:
  5. customStatus: |-
  6. message: "type: "+ context.outputs.service.spec.type +",\t clusterIP:"+ context.outputs.service.spec.clusterIP+",\t ports:"+ "\(context.outputs.service.spec.ports[0].port)"+",\t domain"+context.outputs.ingress.spec.rules[0].host
  7. ...