Status Write Back
This documentation will explain how to achieve status write back by using CUE templates in definition objects.
The spec of health check is , 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.
Trait will not have the context.output
, other fields are the same.
The example of health check likes below:
apiVersion: core.oam.dev/v1beta1
kind: ComponentDefinition
spec:
status:
healthPolicy: |
isHealth: (context.output.status.readyReplicas > 0) && (context.output.status.readyReplicas == context.output.status.replicas)
...
The health check result will be recorded into the Application
resource.
apiVersion: core.oam.dev/v1beta1
kind: Application
spec:
components:
- name: myweb
type: worker
cmd:
- sleep
- "1000"
enemies: alien
image: busybox
lives: "3"
traits:
- type: ingress
properties:
domain: www.example.com
http:
/: 80
status:
...
- healthy: true
message: "type: busybox,\t enemies:alien"
name: myweb
traits:
- healthy: true
message: 'Visiting URL: www.example.com, IP: 47.111.233.220'
type: ingress
status: running
Custom Status
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:
Trait will not have the context.output
, other fields are the same.
apiVersion: core.oam.dev/v1beta1
kind: ComponentDefinition
spec:
status:
customStatus: |-
message: "type: " + context.output.spec.template.spec.containers[0].image + ",\t enemies:" + context.outputs.gameconfig.data.enemies