﻿apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: workflow-instances.synapse.io
spec:
  scope: Namespaced
  names:
    plural: workflow-instances
    singular: workflow-instance
    kind: WorkflowInstance
  group: synapse.io
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                definition:
                  type: object
                  properties:
                    id:
                      type: string
                    version:
                      type: string
                      default: latest
                  required:
                    - id
                    - version
                input:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
                correlationContext:
                  type: object
                  properties:
                    id:
                      type: string
                    contextAttributes:
                      type: object
                      x-kubernetes-preserve-unknown-fields: true
                    bootstrapEvents:
                      type: array
                      items:
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
              required:
                - definition
                - input
            status:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - PENDING
                    - INITIALIZING
                    - DEPLOYED
                    - EXECUTING
                    - SUSPENDED
                    - WAITING
                    - AWAKENING
                    - AWAKENED
                    - FAULTED
                    - EXECUTED
                    - TERMINATED
                    - TIMEDOUT
                correlationContext:
                  type: object
                  properties:
                    id:
                      type: string
                    contextAttributes:
                      type: object
                      x-kubernetes-preserve-unknown-fields: true
                    bootstrapEvents:
                      type: array
                      items:
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                initializedAt:
                  type: string
                deployedAt:
                  type: string
                startedAt:
                  type: string
                executedAt:
                  type: string
                pod:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
                interruptions:
                  type: array
                  items:
                    type: object
                    properties:
                      suspendedAt:
                        type: string
                      resumedAt:
                        type: string
                    required:
                      - suspendedAt
                activityLog:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: string
                      type:
                        type: string
                        enum:
                          - START
                          - STATE
                          - ACTION
                          - EVENT_CONSUME
                          - EVENT_PRODUCE
                          - EVENT_TRIGGER
                          - FUNCTION
                          - BRANCH
                          - SUBFLOW
                          - TRANSITION
                          - ITERATION
                          - END
                          - ERROR
                      status:
                        type: string
                        enum:
                          - PENDING
                          - INITIALIZING
                          - DEPLOYED
                          - EXECUTING
                          - SUSPENDED
                          - FAULTED
                          - EXECUTED
                          - TERMINATED
                          - TIMEDOUT
                      workflowInstance:
                        type: string
                      parentId:
                        type: string
                      createdAt:
                        type: string
                      initializedAt:
                        type: string
                      startedAt:
                        type: string
                      executedAt:
                        type: string
                      data:
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                      metadata:
                        type: object
                        x-kubernetes-preserve-unknown-fields: true
                      result:
                        type: object
                        properties:
                          type:
                            type: string
                            enum:
                              - NEXT
                              - END
                              - TERMINATE
                          output:
                            type: object
                            x-kubernetes-preserve-unknown-fields: true
                        required:
                          - type
                          - output
                      interruptions:
                        type: array
                        items:
                          type: object
                          properties:
                            suspendedAt:
                              type: string
                            resumedAt:
                              type: string
                          required:
                            - suspendedAt
                      errors:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                            message:
                              type: string
                          required:
                            - code
                            - message
                    required:
                      - id
                      - type
                      - status
                      - workflowInstance
                      - createdAt
                errors:
                  type: array
                  items:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                output:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
          required:
            - spec
      subresources:
        status: {}
      additionalPrinterColumns:
        - name: Id
          type: string
          description: The workflow instance's id
          jsonPath: .metadata.name
        - name: Definition Id
          type: string
          description: The workflow instance's definition id
          jsonPath: .spec.definition.id
        - name: Version
          type: string
          description: The workflow instance's definition version
          jsonPath: .spec.definition.version
        - name: Status
          type: string
          description: The workflow instance's status
          jsonPath: .status.type