# Copyright 2020 The Knative Authors
#
# 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: kafkasinks.eventing.knative.dev
  labels:
    duck.knative.dev/addressable: "true"
    knative.dev/crd-install: "true"
    kafka.eventing.knative.dev/release: devel
spec:
  group: eventing.knative.dev
  names:
    kind: KafkaSink
    plural: kafkasinks
    singular: kafkasink
    categories:
      - all
      - knative
      - eventing
  scope: Namespaced
  versions:
    - name: v1alpha1
      served: true
      storage: true
      subresources:
        status: { }
      schema:
        openAPIV3Schema:
          description: 'Kafka Sink is Addressable, it receives events and send them to a Kafka topic.'
          type: object
          properties:
            spec:
              description: 'Spec defines the desired state of the Kafka Sink.'
              type: object
              required:
                - topic
                - bootstrapServers
              properties:
                topic:
                  description: 'Topic name to send events.'
                  type: string
                numPartitions:
                  description: 'Number of topic partitions.
                                If not specified the topic isn''t automatically created, and the system supposes that
                                the topic is already present.'
                  type: integer
                  format: int32
                replicationFactor:
                  description: 'Topic replication factor.
                                If not specified the topic isn''t automatically created, and the system supposes that
                                the topic is already present.'
                  type: integer
                  format: int32
                bootstrapServers:
                  description: 'A list of host/port pairs to use for establishing the initial connection to the Kafka cluster.'
                  type: array
                  minLength: 1
                  items:
                    type: string
                contentMode:
                  description: |
                    CloudEvent content mode of Kafka messages sent to the topic.
                    Possible values: [structured, binary] (default: structured)
                    - https://github.com/cloudevents/spec/blob/v1.0/spec.md#message
                      - https://github.com/cloudevents/spec/blob/v1.0/kafka-protocol-binding.md#33-structured-content-mode
                      - https://github.com/cloudevents/spec/blob/v1.0/kafka-protocol-binding.md#32-binary-content-mode
                  type: string
                  enum:
                    - structured
                    - binary
                  default: structured
            status:
              description: 'Status represents the current state of the Broker. This data may be out of date.'
              type: object
              properties:
                address:
                  description: 'Kafka Sink is Addressable. It exposes the endpoint as an
                      URI to get events delivered into the Broker mesh.'
                  type: object
                  properties:
                    url:
                      type: string
                annotations:
                  description: 'Annotations is additional Status fields for the Resource
                      to save some additional State as well as convey more information
                      to the user. This is roughly akin to Annotations on any k8s resource,
                      just the reconciler conveying richer information outwards.'
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
                conditions:
                  description: 'Conditions the latest available observations of a resource''s
                      current state.'
                  type: array
                  items:
                    type: object
                    required:
                      - type
                      - status
                    properties:
                      lastTransitionTime:
                        description: 'LastTransitionTime is the last time the condition
                            transitioned from one status to another. We use VolatileTime
                            in place of metav1.Time to exclude this from creating
                            equality.Semantic differences (all other things held
                            constant).'
                        type: string
                      message:
                        description: 'A human readable message indicating details
                            about the transition.'
                        type: string
                      reason:
                        description: 'The reason for the condition''s last transition.'
                        type: string
                      severity:
                        description: 'Severity with which to treat failures of
                            this type of condition. When this is not specified,
                            it defaults to Error.'
                        type: string
                      status:
                        description: 'Status of the condition, one of True, False,
                            Unknown.'
                        type: string
                      type:
                        description: 'Type of condition.'
                        type: string
                observedGeneration:
                  description: 'ObservedGeneration is the ''Generation'' of the Service
                      that was last processed by the controller.'
                  type: integer
                  format: int64
      additionalPrinterColumns:
        - name: URL
          type: string
          jsonPath: .status.address.url
        - name: Age
          type: date
          jsonPath: .metadata.creationTimestamp
        - name: Ready
          type: string
          jsonPath: ".status.conditions[?(@.type==\"Ready\")].status"
        - name: Reason
          type: string
          jsonPath: ".status.conditions[?(@.type==\"Ready\")].reason"
#  conversion:
#    strategy: Webhook
#    webhook:
#      conversionReviewVersions: [ "v1alpha1" ]
#      clientConfig:
#        service:
#          name: eventing-kafka-webhook
#          namespace: knative-eventing
