# Copyright 2020 TriggerMesh Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: transformations.flow.triggermesh.io
  labels:
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "*" }
      ]
    registry.knative.dev/eventTypes: |
      [
        { "type": "*" }
      ]
spec:
  group: flow.triggermesh.io
  scope: Namespaced
  names:
    kind: Transformation
    plural: transformations
    categories:
    - all
    - knative
    - eventing
    - transformations
    shortNames:
    - trn
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh CloudEvents transformation engine.
        type: object
        properties:
          spec:
            description: Desired state of the transformation object.
            type: object
            properties:
              context:
                description: CloudEvents Context attributes transformation spec.
                type: array
                items:
                  description: The list of transformation operations executed on the event context sequentially.
                  type: object
                  properties:
                    operation:
                      description: Name of the transformation operation.
                      type: string
                      enum: ['add', 'delete', 'shift', 'store']
                    paths:
                      description: Key-value event pairs to apply the transformations on.
                      type: array
                      items:
                        type: object
                        properties:
                          key:
                            description: JSON path or variable name. Depends on the operation type.
                            nullable: true
                            type: string
                          value:
                            description: JSON path or variable name. Depends on the operation type.
                            nullable: true
                            type: string
                  required:
                  - operation
              data:
                description: CloudEvents Data transformation spec.
                type: array
                items:
                  description: The list of transformation operations executed on the event data sequentially.
                  type: object
                  properties:
                    operation:
                      description: Name of the transformation operation.
                      type: string
                      enum: ['add', 'delete', 'shift', 'store']
                    paths:
                      description: Key-value event pairs to apply the transformations on.
                      type: array
                      items:
                        type: object
                        properties:
                          key:
                            description: JSON path or variable name. Depends on the operation type.
                            nullable: true
                            type: string
                          value:
                            description: JSON path or variable name. Depends on the operation type.
                            nullable: true
                            type: string
                  required:
                  - operation
              sink:
                description: The destination of events sourced from the transformation object.
                type: object
                properties:
                  ref:
                    description: Reference to an addressable Kubernetes object to be used as the destination of events.
                    type: object
                    properties:
                      apiVersion:
                        type: string
                      kind:
                        type: string
                      namespace:
                        type: string
                      name:
                        type: string
                    required:
                    - apiVersion
                    - kind
                    - name
                  uri:
                    description: URI to use as the destination of events.
                    type: string
                    format: uri
                oneOf:
                - required: ['ref']
                - required: ['uri']
          status:
            description: Reported status of Transformation.
            type: object
            properties:
              sinkUri:
                description: URI of the sink where events are currently sent to.
                type: string
                format: uri
              ceAttributes:
                description: CloudEvents context attributes overrides.
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    source:
                      type: string
              observedGeneration:
                type: integer
                format: int64
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    status:
                      type: string
                      enum: ['True', 'False', Unknown]
                    severity:
                      type: string
                      enum: [Error, Warning, Info]
                    reason:
                      type: string
                    message:
                      type: string
                    lastTransitionTime:
                      type: string
                      format: date-time
                  required:
                  - type
                  - status
              address:
                description: Address of the HTTP/S endpoint where Transformation is serving incoming CloudEvents.
                type: object
                properties:
                  url:
                    type: string
    additionalPrinterColumns:
    - name: Address
      type: string
      jsonPath: .status.address.url
    - name: Ready
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].status
    - name: Reason
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].reason
