# Copyright 2021 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: filters.routing.triggermesh.io
  labels:
    triggermesh.io/crd-install: "true"
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "*" }
      ]
    registry.knative.dev/eventTypes: |
      [
        { "type": "*" }
      ]
spec:
  group: routing.triggermesh.io
  scope: Namespaced
  names:
    kind: Filter
    plural: filters
    singular: filter
    categories:
    - all
    - triggermesh
    - routing
    shortNames:
    - fl
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh content-based events filter.
        type: object
        properties:
          spec:
            description: Desired state of the filter.
            type: object
            required:
            - expression
            - sink
            properties:
              expression:
                description: Google CEL-like expression string.
                type: string
              sink:
                description: Sink is a reference to an object that will resolve to
                    a uri to use as the sink.
                type: object
                oneOf:
                - required: [ref]
                - required: [uri]
                properties:
                  ref:
                    description: Ref points to an Addressable.
                    type: object
                    properties:
                      apiVersion:
                        description: API version of the referent.
                        type: string
                      kind:
                        description: 'Kind of the referent. More info:
                          https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                        type: string
                      name:
                        description: 'Name of the referent. More info:
                          https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
                        type: string
                      namespace:
                        description: 'Namespace of the referent. More info:
                          https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
                          This is optional field, it gets defaulted to the object holding it if left out.'
                        type: string
                  uri:
                    description: URI can be an absolute URL(non-empty scheme and
                      non-empty host) pointing to the target or a relative URI.
                      Relative URIs will be resolved using the base URI retrieved
                      from Ref.
                    type: string
          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:
                type: object
                properties:
                  url:
                    type: string
              sinkUri:
                description: URI of the sink where events are currently sent to.
                type: string
                format: uri
    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
