apiVersion: core.oam.dev/v1beta1
kind: ComponentDefinition
metadata:
  annotations:
    definition.oam.dev/alias: Deployment
    definition.oam.dev/description: Deployment
  name: deployment-with-status
  namespace: vela-system
spec:
  schematic:
    cue:
      template: |
        output: {
          apiVersion: "apps/v1"
          kind:       "Deployment"

          metadata: {
            name: "deployment-with-status"
          }

          spec: {
            replicas: 2
        
            selector: matchLabels: {
              app: "deployment-with-status"
            }

            template: {
              metadata: labels: {
                app: "deployment-with-status"
              }

              spec: {
                containers: [{
                  name:  "deployment-with-status"
                  image: "nginx"
                }]
              }
            }
          }
        }
  status:
    details: |
      deploymentReady: *(context.output.status.replicas == context.output.status.readyReplicas) | false
      $expectedReplicas: context.output.spec.replicas
      readyReplicas: *context.output.status.readyReplicas | 0
    healthPolicy: |
      isHealth: context.status.details.readyReplicas == context.status.details.$expectedReplicas
    customStatus: |
      if context.status.healthy {
        message: "Healthy - \(context.status.details.readyReplicas) / \(context.status.details.$expectedReplicas) replicas are ready"
      }
      if !context.status.healthy {
        message: "Unhealthy - \(context.status.details.readyReplicas) / \(context.status.details.$expectedReplicas) replicas are ready"
      }
  workload:
    definition:
      apiVersion: apps/v1
      kind: Deployment