# 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: googlecloudsourcerepositoriessources.sources.triggermesh.io
  labels:
    eventing.knative.dev/source: 'true'
    duck.knative.dev/source: 'true'
    knative.dev/crd-install: 'true'
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.knative.dev/eventTypes: |
      [
        { "type": "com.google.cloud.sourcerepo.notification" }
      ]
spec:
  group: sources.triggermesh.io
  scope: Namespaced
  names:
    kind: GoogleCloudSourceRepositoriesSource
    plural: googlecloudsourcerepositoriessources
    categories:
    - all
    - knative
    - eventing
    - sources
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh event source for Google Cloud Source Repositories.
        type: object
        properties:
          spec:
            description: Desired state of the event source.
            type: object
            properties:
              repository:
                description: Full resource name of the Repository.
                type: string
                pattern: ^projects\/[a-z][a-z0-9-]{3,29}\/repos\/[a-zA-Z][\w-.~%+]{2,254}$
              pubsub:
                description: Attributes related to the configuration of Pub/Sub resources associated with the Cloud Repositories.
                type: object
                properties:
                  topic:
                    description: Full resource name of the Pub/Sub topic where change notifications originating from the configured
                      repo are sent to, before being retrieved by this event source. If not supplied, a topic is created on
                      behalf of the user, in the GCP project referenced by the 'project' attribute. The expected format is
                      described at https://cloud.google.com/pubsub/docs/admin#resource_names
                    type: string
                    pattern: ^projects\/[a-z][a-z0-9-]{3,29}\/topics\/[a-zA-Z][\w-.~%+]{2,254}$
                required: [topic]
              publishServiceAccount:
                description: |-
                  Email address of the service account used for publishing notifications to Pub/Sub. This service
                  account needs to be in the same project as the repo, and to have the 'pubsub.topics.publish' IAM
                  permission associated with it. It can (but doesn't have to) be the same service account as the
                  'serviceAccountKey' attribute.

                  If unspecified, it defaults to the Compute Engine default service account.
                type: string
                format: email
              serviceAccountKey:
                description: Service account key used to authenticate the event source and allow it to interact with Google
                  Cloud APIs. Only the JSON format is supported.
                type: object
                properties:
                  value:
                    description: Literal value of the service account key.
                    type: string
                  valueFromSecret:
                    description: A reference to a Kubernetes Secret object containing the service account key.
                    type: object
                    properties:
                      name:
                        type: string
                      key:
                        type: string
                    required:
                    - name
                    - key
                oneOf:
                - required: [value]
                - required: [valueFromSecret]
              sink:
                description: The destination of events received via change notifications.
                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]
              adapterOverrides:
                description: Kubernetes object parameters to apply on top of default adapter values.
                type: object
                properties:
                  resources:
                    description: Compute Resources required by the adapter. More info at 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 at 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 at 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
            required:
            - repository
            - serviceAccountKey
            - sink
          status:
            description: Reported status of the event source.
            type: object
            properties:
              topic:
                description: Resource name of the Pub/Sub topic where repositories events are currently sent to.
                type: string
              subscription:
                description: Resource name of the Pub/Sub subscription currently used by the event source for pulling events
                  from repositories.
                type: string
              sinkUri:
                description: URI of the sink where events are currently sent to.
                type: string
                format: uri
              ceAttributes:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    source:
                      type: string
                  required:
                  - type
                  - source
              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
    additionalPrinterColumns:
    - name: Ready
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].status
    - name: Reason
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].reason
    - name: Sink
      type: string
      jsonPath: .status.sinkUri
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
