github.com/oam-dev/kubevela@v1.9.11/docs/examples/app-with-status/template.yaml (about) 1 apiVersion: core.oam.dev/v1beta1 2 kind: ComponentDefinition 3 metadata: 4 name: nworker 5 annotations: 6 definition.oam.dev/description: "Describes long-running, scalable, containerized services that running at backend. They do NOT have network endpoint to receive external network traffic." 7 spec: 8 workload: 9 definition: 10 apiVersion: apps/v1 11 kind: Deployment 12 status: 13 healthPolicy: | 14 isHealth: (context.output.status.readyReplicas > 0) && (context.output.status.readyReplicas == context.output.status.replicas) 15 customStatus: |- 16 message: "type: " + context.output.spec.template.spec.containers[0].image + ",\t enemies:" + context.outputs.gameconfig.data.enemies 17 schematic: 18 cue: 19 template: | 20 output: { 21 apiVersion: "apps/v1" 22 kind: "Deployment" 23 spec: { 24 selector: matchLabels: { 25 "app.oam.dev/component": context.name 26 } 27 28 template: { 29 metadata: labels: { 30 "app.oam.dev/component": context.name 31 } 32 33 spec: { 34 containers: [{ 35 name: context.name 36 image: parameter.image 37 envFrom: [{ 38 configMapRef: name: context.name + "game-config" 39 }] 40 if parameter["cmd"] != _|_ { 41 command: parameter.cmd 42 } 43 }] 44 } 45 } 46 } 47 } 48 49 outputs: gameconfig: { 50 apiVersion: "v1" 51 kind: "ConfigMap" 52 metadata: { 53 name: context.name + "game-config" 54 } 55 data: { 56 enemies: parameter.enemies 57 lives: parameter.lives 58 } 59 } 60 61 parameter: { 62 // +usage=Which image would you like to use for your service 63 // +short=i 64 image: string 65 // +usage=Commands to run in the container 66 cmd?: [...string] 67 lives: string 68 enemies: string 69 } 70 71 72 --- 73 apiVersion: core.oam.dev/v1beta1 74 kind: TraitDefinition 75 metadata: 76 name: ingress 77 spec: 78 status: 79 customStatus: |- 80 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 81 healthPolicy: | 82 isHealth: len(context.outputs.service.spec.clusterIP) > 0 83 podDisruptive: false 84 schematic: 85 cue: 86 template: | 87 parameter: { 88 domain: string 89 http: [string]: int 90 } 91 // trait template can have multiple outputs in one trait 92 outputs: service: { 93 apiVersion: "v1" 94 kind: "Service" 95 spec: { 96 selector: 97 app: context.name 98 ports: [ 99 for k, v in parameter.http { 100 port: v 101 targetPort: v 102 }, 103 ] 104 } 105 } 106 outputs: ingress: { 107 apiVersion: "networking.k8s.io/v1beta1" 108 kind: "Ingress" 109 metadata: 110 name: context.name 111 spec: { 112 rules: [{ 113 host: parameter.domain 114 http: { 115 paths: [ 116 for k, v in parameter.http { 117 path: k 118 backend: { 119 serviceName: context.name 120 servicePort: v 121 } 122 }, 123 ] 124 } 125 }] 126 } 127 }