apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  name: predownloadimage
spec:
  schematic:
    cue:
      template: |
        import ("vela/op")
        parameter: {
          image: string
          parallel: int
          kvs: [string]: string
          type: *"Always" | string
          activeDeadlineSeconds: *1200 | int
          ttlSecondsAfterFinished: *300 | int
          backoffLimit?: int
          timeoutSeconds?: int
          arr: [...string]
        }

        pullImageJob: op.#Apply & {
          value:{
            apiVersion: "apps.kruise.io/v1alpha1"
            kind:       "ImagePullJob"
            metadata: {
              name: "pull-image-job"
            }
            spec: {
              image: parameter.image
              parallelism: parameter.parallel
              selector: matchLabels: parameter.kvs
              completionPolicy: {
                type: parameter.type
                activeDeadlineSeconds: parameter.activeDeadlineSeconds
                ttlSecondsAfterFinished: parameter.ttlSecondsAfterFinished
              }
              pullPolicy: {
                if parameter.backoffLimit != _|_ {
                  backoffLimit: parameter.backoffLimit
                }
                if parameter.timeoutSeconds != _|_ {
                  timeoutSeconds: parameter.timeoutSeconds
                }
              }
              pullSecrets: parameter.arr
            }            
          }          
        }