# 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: functions.extensions.triggermesh.io
  labels:
    triggermesh.io/crd-install: "true"
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "*" }
      ]
    registry.knative.dev/eventTypes: |
      [
        { "type": "*" }
      ]
spec:
  group: extensions.triggermesh.io
  scope: Namespaced
  names:
    kind: Function
    plural: functions
    singular: function
    categories:
    - all
    - triggermesh
    - extensions
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh Function.
        type: object
        properties:
          spec:
            description: Desired state of the function.
            type: object
            required:
            - runtime
            - entrypoint
            - code
            properties:
              adapterOverrides:
                description: Kubernetes object parameters to apply on top of default adapter values.
                type: object
                properties:
                  public:
                    description: Adapter visibility scope.
                    type: boolean
                  resources:
                    description: 'Compute Resources required by the adapter. More info:
                      https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
                    type: object
                    properties:
                      limits:
                        additionalProperties:
                          anyOf:
                          - type: integer
                          - type: string
                          pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                          x-kubernetes-int-or-string: true
                        description: 'Limits describes the maximum amount of compute resources allowed. More info:
                          https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
                        type: object
                      requests:
                        additionalProperties:
                          anyOf:
                          - type: integer
                          - type: string
                          pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                          x-kubernetes-int-or-string: true
                        description: 'Requests describes the minimum amount of compute resources required.
                          If Requests is omitted for a container, it defaults to Limits if that is explicitly
                          specified, otherwise to an implementation-defined value. More info:
                          https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
                        type: object
                  tolerations:
                    description: Pod tolerations, as documented at
                      https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
                    type: array
                    items:
                      type: object
                      properties:
                        key:
                          description: Taint key that the toleration applies to.
                          type: string
                        operator:
                          description: Key's relationship to the value.
                          type: string
                          enum: [Exists, Equal]
                        value:
                          description: Taint value the toleration matches to.
                          type: string
                        effect:
                          description: Taint effect to match.
                          type: string
                          enum: [NoSchedule, PreferNoSchedule, NoExecute]
                        tolerationSeconds:
                          description: Period of time a toleration of effect NoExecute tolerates the taint.
                          type: integer
                          format: int64
              runtime:
                description: Function runtime name. Python, Ruby or Node runtimes are currently supported.
                type: string
                enum: [python, ruby, node]
              code:
                description: Function code.
                type: string
              entrypoint:
                description: Function name to use as an entrypoint.
                type: string
              responseIsEvent:
                description: Whether function responds with CE payload only or with full event.
                type: boolean
              eventStore:
                description: EventStore service connection string.
                type: object
                properties:
                  uri:
                    type: string
                required:
                - uri
              ceOverrides:
                type: object
                description: Defines overrides to control modifications of the event attributes.
                properties:
                  extensions:
                    type: object
                    properties:
                      type:
                        type: string
                      source:
                        type: string
                      subject:
                        type: string
                required:
                - extensions
              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:
              configMap:
                description: Identity of the ConfigMap containing the code of the Function.
                type: object
                properties:
                  name:
                    description: Name of the ConfigMap.
                    type: string
                  resourceVersion:
                    description: Observed revision of the ConfigMap.
                    type: string
                required:
                - name
                - resourceVersion
              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: 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
