# 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: synchronizers.flow.triggermesh.io
  labels:
    duck.knative.dev/addressable: 'true'
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "*" }
      ]
spec:
  group: flow.triggermesh.io
  names:
    kind: Synchronizer
    plural: synchronizers
    categories:
    - all
    - knative
    - eventing
    - flow
  scope: Namespaced
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            description: Desired state of the event synchronizer.
            type: object
            properties:
              correlationKey:
                description: Events correlation parameters.
                type: object
                properties:
                  attribute:
                    description: The name of the correlation key that will be injected into the CloudEvents context.
                      Events without this attribute are forwarded to the Sink as the client requests while client
                      connections are held open. Events, which context already has the correlation key, are sent back
                      to the open client connections.
                    type: string
                  length:
                    description: The length of the correlation key to generate. The default value is 24.
                    type: integer
                    minimum: 1
                    maximum: 64
                    default: 24
                required:
                - attribute
              response:
                description: Responses handling configuration.
                type: object
                properties:
                  timeout:
                    description: The time during which the synchronizer will block the client and wait for the
                      response. Expressed as a duration string, which format is documented at
                      https://pkg.go.dev/time#ParseDuration.
                    type: string
                required:
                - timeout
              sink:
                description: The destination where the synchronizer will forward incoming requests from the clients.
                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]
            required:
            - correlationKey
            - response
            - sink
          status:
            type: object
            description: Reported status of the event synchronizer.
            properties:
              sinkUri:
                description: URI of the sink where events are currently sent to.
                type: string
                format: uri
              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:
                type: object
                properties:
                  url:
                    type: string
    additionalPrinterColumns:
    - name: URL
      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
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
