---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: consumers.jetstream.nats.io
spec:
  group: jetstream.nats.io
  scope: Namespaced
  names:
    kind: Consumer
    singular: consumer
    plural: consumers
    shortNames:
    - cns
  versions:
  - name: v1beta1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              streamName:
                description: The name of the Stream to create the Consumer in.
                type: string
              deliverPolicy:
                type: string
                enum:
                - all
                - last
                - new
                # Requires optStartSeq
                - byStartSequence
                # Requires optStartTime
                - byStartTime
                default: all
              optStartSeq:
                type: integer
                minimum: 0
              optStartTime:
                description: Time format must be RFC3339.
                type: string
              durableName:
                description: The name of the Consumer.
                type: string
                pattern: '^[^.*>]+$'
                minLength: 1
              deliverSubject:
                description: The subject to deliver observed messages, when not set, a pull-based Consumer is created.
                type: string
              ackPolicy:
                description: How messages should be acknowledged.
                type: string
                enum:
                - none
                - all
                - explicit
                default: none
              ackWait:
                description: How long to allow messages to remain un-acknowledged before attempting redelivery.
                type: string
                default: 1ns
              maxDeliver:
                type: integer
                minimum: -1
              filterSubject:
                description: Select only a specific incoming subjects, supports wildcards.
                type: string
              replayPolicy:
                description: How messages are sent.
                type: string
                enum:
                - instant
                - original
                default: instant
              sampleFreq:
                description: What percentage of acknowledgements should be samples for observability.
                type: string
              rateLimitBps:
                description: rate at which messages will be delivered to clients, expressed in bit per second.
                type: integer
          status:
            type: object
            properties:
              observedGeneration:
                type: integer
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    status:
                      type: string
                    lastTransitionTime:
                      type: string
                    reason:
                      type: string
                    message:
                      type: string
    additionalPrinterColumns:
    - name: State
      type: string
      description: The current state of the consumer.
      jsonPath: .status.conditions[?(@.type == 'Ready')].reason
    - name: Stream
      type: string
      description: The name of the Jetstream Stream.
      jsonPath: .spec.streamName
    - name: Consumer
      type: string
      description: The name of the Jetstream Consumer.
      jsonPath: .spec.durableName
    - name: Ack Policy
      type: string
      description: The ack policy.
      jsonPath: .spec.ackPolicy
