apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  name: apply-base
  namespace: vela-system
spec:
  schematic:
    cue:
      template: |-
        import ("vela/op")
        parameter: {
           component: string
        }
        load: op.#Load

        apply: op.#ApplyComponent & {
           value: load.value[parameter.component]
        }

        workload: apply.output
        // wait until deployment ready
        wait: op.#ConditionalWait & {
           continue: workload.status.readyReplicas == workload.status.replicas && workload.status.observedGeneration == workload.metadata.generation
        }

        // export service ClusterIP
        clusterIP: apply.outputs["service"].value.spec.clusterIP
---
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  name: apply-helm
  namespace: vela-system
spec:
  schematic:
    cue:
      template: |-
        import ("vela/op")
        parameter: {
           component: string
        }
        load: op.#Load

        apply: op.#ApplyComponent & {
           value: load.value[parameter.component]
        }

        // wait redis ready
        wait: op.#ConditionalWait & {
           // todo
           continue: true
        }
---
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  name: apply-proxy
  namespace: vela-system
spec:
  schematic:
    cue:
      template: |-
        import (
           "vela/op"
           "encoding/json"
        )
        parameter: {
           component: string
           backendIP: string
        }

        // 往三方配置中心apollo读取配置
        // config: op.#HTTPGet

        load: op.#Load

        apply: op.#ApplyComponent & {
           value: load.value[parameter.component]
           // 给环境变量中注入BackendIP
           patch: workload: spec: template: spec: {
             containers: [{
                // patchKey=name
                env: [{name: "BackendIP",value: parameter.backendIP}]
             },...]
           }
        }

        workload: apply.output
        // wait until argo.rollout ready
        wait: op.#ConditionalWait & {
           continue: workload.status.readyReplicas == workload.status.replicas && workload.status.observedGeneration == workload.metadata.generation
        }

        message: {...}
        // 往三方配置中心apollo写配置
        notify: op.#HTTPPost & {
           url: "appolo-address"
           request: body: json.Marshal(message)
        }
