# 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: azureeventhubstargets.targets.triggermesh.io
  labels:
    eventing.knative.dev/target: 'true'
    duck.knative.dev/target: 'true'
    knative.dev/crd-install: 'true'
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.triggermesh.io/acceptedEventTypes: |
      [
        { "type": "*" }
      ]
    registry.knative.dev/eventTypes: |
      [
        { "type": "io.triggermesh.azure.eventhubs.put.response" }
      ]

spec:
  group: targets.triggermesh.io
  scope: Namespaced
  names:
    kind: AzureEventHubsTarget
    plural: azureeventhubstargets
    categories:
    - all
    - knative
    - eventing
    - targets
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh event target for Azure Event Hubs.
        type: object
        properties:
          spec:
            description: Desired state of the event target.
            type: object
            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
              eventHubID:
                description: |-
                  Resource ID of the Event Hubs instance.

                  The expected format is
                    /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs/{eventHubName}
                type: string
                pattern: ^\/subscriptions\/[a-z0-9-]+\/resourceGroups\/[\w.()-]+\/providers\/Microsoft.EventHub\/namespaces\/[A-Za-z0-9-]{6,50}\/event[Hh]ubs\/[a-zA-Z0-9][\w.-]{0,49}$
              discardCloudEventContext:
                description: Whether to omit CloudEvent context attributes in objects created in Azure Event Hub.
                  When this property is false (default), the entire CloudEvent payload is included.
                  When this property is true, only the CloudEvent data is included.
                type: boolean
              auth:
                description: Authentication method to interact with the Azure Event Hubs REST API.
                type: object
                properties:
                  sasToken:
                    description: An Azure shared access signature (SAS) token. For more information about SAS tokens,
                      please refer to the Azure Storage documentation at
                      https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview.
                    type: object
                    properties:
                      keyName:
                        description: Name of the key used by the SAS token. Mutually exclusive with 'connectionString'.
                        type: object
                        properties:
                          value:
                            description: Literal name of the key.
                            type: string
                          valueFromSecret:
                            description: A reference to a Kubernetes Secret object containing the key's name.
                            type: object
                            properties:
                              name:
                                type: string
                              key:
                                type: string
                            required:
                            - name
                            - key
                        oneOf:
                        - required: [value]
                        - required: [valueFromSecret]
                      keyValue:
                        description: Value of the key used by the SAS token. Mutually exclusive with 'connectionString'.
                        type: object
                        properties:
                          value:
                            description: Literal value of the key.
                            type: string
                          valueFromSecret:
                            description: A reference to a Kubernetes Secret object containing the key's value.
                            type: object
                            properties:
                              name:
                                type: string
                              key:
                                type: string
                            required:
                            - name
                            - key
                        oneOf:
                        - required: [value]
                        - required: [valueFromSecret]
                      connectionString:
                        description: Connection string containing both the resource URI of the Event Hubs instance, and
                          the SAS token. Mutually exclusive with 'keyName' and 'keyValue'.
                        type: object
                        properties:
                          value:
                            description: Literal value of the connection string.
                            type: string
                          valueFromSecret:
                            description: A reference to a Kubernetes Secret object containing the connection string.
                            type: object
                            properties:
                              name:
                                type: string
                              key:
                                type: string
                            required:
                            - name
                            - key
                        oneOf:
                        - required: [value]
                        - required: [valueFromSecret]
                    oneOf:
                    - required:
                      - keyName
                      - keyValue
                    - required:
                      - connectionString
                  servicePrincipal:
                    description: Credentials of an Azure Service Principal. For more information about service
                      principals, please refer to the Azure Active Directory documentation at
                      https://docs.microsoft.com/en-us/azure/active-directory/develop/app-objects-and-service-principals.
                    type: object
                    properties:
                      tenantID:
                        description: ID of the Azure Active Directory tenant.
                        type: object
                        properties:
                          value:
                            description: Literal value of the tenant ID.
                            type: string
                            format: guid
                            pattern: ^[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}$
                          valueFromSecret:
                            description: A reference to a Kubernetes Secret object containing the tenant ID.
                            type: object
                            properties:
                              name:
                                type: string
                              key:
                                type: string
                            required:
                            - name
                            - key
                        oneOf:
                        - required: [value]
                        - required: [valueFromSecret]
                      clientID:
                        description: ID of the registered client/application.
                        type: object
                        properties:
                          value:
                            description: Literal value of the client ID.
                            type: string
                            format: guid
                            pattern: ^[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}$
                          valueFromSecret:
                            description: A reference to a Kubernetes Secret object containing the client ID.
                            type: object
                            properties:
                              name:
                                type: string
                              key:
                                type: string
                            required:
                            - name
                            - key
                        oneOf:
                        - required: [value]
                        - required: [valueFromSecret]
                      clientSecret:
                        description: Secret associated with the registered client/application.
                        type: object
                        properties:
                          value:
                            description: Literal value of the client secret.
                            type: string
                            format: password
                          valueFromSecret:
                            description: A reference to a Kubernetes Secret object containing the client secret.
                            type: object
                            properties:
                              name:
                                type: string
                              key:
                                type: string
                            required:
                            - name
                            - key
                        oneOf:
                        - required: [value]
                        - required: [valueFromSecret]
                    required:
                    - tenantID
                    - clientID
                    - clientSecret
                oneOf:
                - required: [sasToken]
                - required: [servicePrincipal]
            required:
            - eventHubID
            - auth
          status:
            description: Reported status of the event target.
            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
    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
