# Copyright 2021 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: resetoffsets.kafka.eventing.knative.dev
  labels:
    kafka.eventing.knative.dev/release: devel
    knative.dev/crd-install: "true"
spec:
  group: kafka.eventing.knative.dev
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: { }
    schema:
      openAPIV3Schema:
        description: 'ResetOffset is a one-time "command" or "request" indicating the desire to
            reposition the Kafka Topic/Partition Offsets of a specific ConsumerGroup as referenced
            by a Subscription / Trigger, etc.  The ResetOffset status tracks the progress of the
            steps involved in this repositioning. Once the Succeeded status is set (true / false),
            the ResetOffset is "finished" and cannot be re-executed.  Another ResetOffset will be
            required in order to make another attempt once the underlying issue has been resolved.'
        type: object
        properties:
          spec:
            description: 'Specifies the desired "time" to reposition the Offsets, as well as
                a reference object which is used to identify the specific ConsumerGroups to be
                repositioned.'
            type: object
            properties:
              offset:
                description: 'Wrapper containing various options for specifying the desired Offset.
                Currently only the "time" option is provided, but this will allow for additional
                configuration (e.g. explicit partition/offset values) to be added in the future.'
                type: object
                properties:
                  time:
                    description: 'String defining the time to which the Kafka Topic / Partition
                    Offsets will be reset. Supported values include "earliest", "latest", or a
                    valid date / time string in the RFC3339 format (e.g. "2021-05-04T05:04:01Z").
                    The "earliest" and "latest" values indicate the beginning and end, respectively,
                    of the persistence window of the Topic. There is no guarantee of precision, and
                    the exact time/offset will depend on the state of the persistence window when
                    the ResetOffset command is executed. There is no default value, and invalid
                    values will result in the ResetOffset operation being rejected as failed.'
                    type: string
              ref:
                description: 'Reference to a Kafka resource which can be mapped to a specific
                    ConsumerGroup, such as a Subscription or Trigger. This open type allows various
                    implementations (Channels, Brokers, etc) to support the ResetOffset CRD without
                    changing the schema. Each such implementation is responsible for validating and
                    rejecting unsupported referenced types.  For example, the KafkaChannel Controller
                    will only support Subscriptions and will reject any other reference type, while
                    the KafkaBroker implementation might do the same for Triggers.  Check your
                    specific use case to determine what resource types are supported! There is no
                    default value, and invalid values will result in the ResetOffset operation being
                    rejected as failed.'
                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/'
                    type: string
          status:
            description: "Status (computed) for a ResetOffset"
            type: object
            properties:
              topic:
                description: 'The Kafka Topic name associated with the specified Spec.Ref instance.'
                type: string
              group:
                description: 'The Kafka ConsumerGroup ID associated with the specified Spec.Ref instance.'
                type: string
              partitions:
                description: 'The Offset information for each Kafka Partition associated with the specified Spec.Ref instance.'
                type: array
                items:
                  type: object
                  properties:
                    partition:
                      description: 'The Partition number for the associated Topic / ConsumerGroup.'
                      type: integer
                    oldOffset:
                      description: 'The current Offset of the Kafka Partition prior to being reset.'
                      type: integer
                    newOffset:
                      description: 'The new Offset to which the Kafka Partition will be reset.'
                      type: integer
              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 is the latest available observations of a resource''s current state.'
                type: array
                items:
                  type: object
                  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: Succeeded
      type: string
      jsonPath: ".status.conditions[?(@.type==\"Succeeded\")].status"
    - name: Reason
      type: string
      jsonPath: ".status.conditions[?(@.type==\"Succeeded\")].reason"
    - name: Ref Namespace
      type: string
      jsonPath: ".spec.ref.namespace"
      priority: 1
    - name: Ref Name
      type: string
      jsonPath: ".spec.ref.name"
      priority: 1
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
  names:
    kind: ResetOffset
    plural: resetoffsets
    singular: resetoffset
    categories:
    - all
    - knative
    - eventing
    - kafka
    shortNames:
    - ro
  scope: Namespaced
