github.com/oam-dev/kubevela@v1.9.11/docs/examples/application/template.yaml (about)

     1  apiVersion: core.oam.dev/v1beta1
     2  kind: ComponentDefinition
     3  metadata:
     4    name: worker
     5    annotations:
     6      definition.oam.dev/description: "Long-running scalable backend worker without network endpoint"
     7  spec:
     8    workload:
     9      definition:
    10        apiVersion: apps/v1
    11        kind: Deployment
    12    schematic:
    13      cue:
    14        template: |
    15          output: {
    16            apiVersion: "apps/v1"
    17            kind:       "Deployment"
    18            spec: {
    19                selector: matchLabels: {
    20                    "app.oam.dev/component": context.name
    21                }
    22  
    23                template: {
    24                    metadata: labels: {
    25                        "app.oam.dev/component": context.name
    26                    }
    27  
    28                    spec: {
    29                        containers: [{
    30                            name:  context.name
    31                            image: parameter.image
    32  
    33                            if parameter["cmd"] != _|_ {
    34                                command: parameter.cmd
    35                            }
    36                        }]
    37                    }
    38                }
    39  
    40                selector:
    41                    matchLabels:
    42                        "app.oam.dev/component": context.name
    43            }
    44          }
    45  
    46          parameter: {
    47            // +usage=Which image would you like to use for your service
    48            // +short=i
    49            image: string
    50  
    51            cmd?: [...string]
    52          }
    53  ---
    54  apiVersion: core.oam.dev/v1beta1
    55  kind: TraitDefinition
    56  metadata:
    57    annotations:
    58      definition.oam.dev/description: "Manually scale the app"
    59    name: scaler
    60  spec:
    61    appliesToWorkloads:
    62      - deployments.apps
    63    schematic:
    64      cue:
    65        template: |-
    66          patch: {
    67             spec: replicas: parameter.replicas
    68          }
    69          parameter: {
    70            //+short=r
    71            replicas: *1 | int
    72          }
    73  ---
    74  apiVersion: core.oam.dev/v1beta1
    75  kind: TraitDefinition
    76  metadata:
    77    annotations:
    78      definition.oam.dev/description: "add sidecar to the app"
    79    name: sidecar
    80  spec:
    81    appliesToWorkloads:
    82      - deployments.apps
    83    schematic:
    84      cue:
    85        template: |-
    86          patch: {
    87             // +patchKey=name
    88             spec: template: spec: containers: [parameter]
    89          }
    90          parameter: {
    91             name: string
    92             image: string
    93             command?: [...string]
    94          }
    95  ---
    96  apiVersion: core.oam.dev/v1beta1
    97  kind: TraitDefinition
    98  metadata:
    99    annotations:
   100      definition.oam.dev/description: "service the app"
   101    name: kservice
   102  spec:
   103    appliesToWorkloads:
   104      - deployments.apps
   105    schematic:
   106      cue:
   107        template: |-
   108          patch: {spec: template: metadata: labels: app: context.name}
   109          outputs: service: {
   110            apiVersion: "v1"
   111            kind: "Service"
   112            metadata: name: context.name
   113            spec: {
   114              selector:  app: context.name
   115              ports: [
   116                for k, v in parameter.http {
   117                  port: v
   118                  targetPort: v
   119                }
   120              ]
   121            }
   122          }
   123          parameter: {
   124            http: [string]: int
   125          }
   126  ---
   127  apiVersion: core.oam.dev/v1beta1
   128  kind: TraitDefinition
   129  metadata:
   130    name: services
   131    namespace: default
   132  spec:
   133    definitionRef:
   134      name: services