# Copyright 2022 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: xslttransformations.flow.triggermesh.io
  labels:
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "*" }
      ]
    registry.knative.dev/eventTypes: |
      [
        { "type": "io.triggermesh.xslttransformation.error" },
        { "type": "*" }
      ]
spec:
  group: flow.triggermesh.io
  scope: Namespaced
  names:
    kind: XSLTTransformation
    plural: xslttransformations
    categories:
    - all
    - knative
    - eventing
    - triggermesh
    - transformations
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh CloudEvents XSLT transformation.
        type: object
        properties:
          spec:
            description: Desired state of the TriggerMesh component.
            type: object
            properties:
              xslt:
                description: XSLT used to transform incoming CloudEvents.
                type: object
                properties:
                  value:
                    description: Literal inline value.
                    type: string
                  valueFromSecret:
                    description: A reference to a Kubernetes Secret object containing the value.
                    type: object
                    properties:
                      name:
                        type: string
                      key:
                        type: string
                    required:
                    - name
                    - key
                  valueFromConfigMap:
                    description: A reference to a Kubernetes ConfigMap object containing the value.
                    type: object
                    properties:
                      name:
                        type: string
                      key:
                        type: string
                    required:
                    - name
                    - key
                oneOf:
                - required: [value]
                - required: [valueFromSecret]
                - required: [valueFromConfigMap]
              allowPerEventXSLT:
                description: Whether the XSLT informed at the spec can be overriden at each CloudEvent.
                type: boolean
              sink:
                description: The destination of events transformed by this component.
                type: object
                properties:
                  ref:
                    description: Reference to an addressable Kubernetes object to be used as the destination of events.
                     If left empty, the events will be sent back to the sender/source.
                    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']
            anyOf:
            - required: [xslt]
            - required: [allowPerEventXSLT]
          status:
            description: Reported status.
            type: object
            properties:
              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 component is listening for 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
