apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  name: dispatch-comp-rev
  namespace: vela-system
spec:
  schematic:
    cue:
      template: |
        import ("vela/op")

        componentRev: op.#Read & {
        	value: {
               kind: "ControllerRevision"
               apiVersion: "apps/v1"
               metadata: {
                  name: parameter.compRev
                  namespace: context.namespace
               }
            }
        }

        apply: op.#Apply & {
            value: {
                apiVersion: "work.open-cluster-management.io/v1"
                kind: "ManifestWork"
                metadata: {
                   namespace: parameter.cluster
                   name: "comprevision-" + parameter.compRev
                }
                spec: {
                   workload: {
                      manifests: [{
                         kind: "ControllerRevision"
                         apiVersion: "apps/v1"
                         metadata: {
                            name: parameter.compRev
                            namespace: context.namespace
                         }
                         data: {
                            apiVersion: "core.oam.dev/v1alpha2"
                            kind: "Component"
                            metadata:
                              name: context.name
                              namespace: context.namespace
                            spec:
                              workload: {
                                  componentRev.value.data.spec.workload
                              }
                         }
                      }]
                   }
                }
            }
        }

        parameter: {
          compRev: string
          cluster: string
        }