apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: hawkbits.iot.eclipse.org
spec:
  group: iot.eclipse.org
  scope: Namespaced

  names:
    plural: hawkbits
    singular: hawkbit
    kind: Hawkbit

  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:

                imageOverrides:
                  type: object
                  additionalProperties:
                    type: object
                    properties:
                      image:
                        type: string
                      pullPolicy:
                        type: string

                signOn:
                  type: object
                  properties:
                    keycloak:
                      type: object
                      properties:
                        instanceSelector:
                          description: Selector for looking up Keycloak Custom Resources.
                          properties:
                            matchExpressions:
                              description: matchExpressions is a list of label selector requirements.
                                The requirements are ANDed.
                              items:
                                description: A label selector requirement is a selector that contains
                                  values, a key, and an operator that relates the key and values.
                                properties:
                                  key:
                                    description: key is the label key that the selector applies
                                      to.
                                    type: string
                                  operator:
                                    description: operator represents a key's relationship to a
                                      set of values. Valid operators are In, NotIn, Exists and
                                      DoesNotExist.
                                    type: string
                                  values:
                                    description: values is an array of string values. If the operator
                                      is In or NotIn, the values array must be non-empty. If the
                                      operator is Exists or DoesNotExist, the values array must
                                      be empty. This array is replaced during a strategic merge
                                      patch.
                                    items:
                                      type: string
                                    type: array
                                required:
                                  - key
                                  - operator
                                type: object
                              type: array
                            matchLabels:
                              additionalProperties:
                                type: string
                              description: matchLabels is a map of {key,value} pairs. A single
                                {key,value} in the matchLabels map is equivalent to an element
                                of matchExpressions, whose key field is "key", the operator is
                                "In", and the values array contains only "value". The requirements
                                are ANDed.
                              type: object
                          type: object
                        hawkbitUrl:
                          type: string

                rabbit:
                  type: object
                  oneOf:
                    - required: [ "external" ]
                    - required: [ "managed" ]
                  properties:
                    external:
                      type: object
                      required: [ "host" ]
                      properties:
                        host:
                          type: string
                        port:
                          type: integer
                        username:
                          type: string
                        passwordSecret:
                          type: object
                          properties:
                            name:
                              type: string
                            field:
                              type: string

                    managed:
                      type: object
                      properties:
                        storageSize:
                          type: string
                        resources:
                          type: object

                database:
                  type: object

                  oneOf:
                    - required: [ "mysql" ]
                    - required: [ "postgres" ]
                    - required: [ "embedded" ]

                  properties:

                    mysql:
                      type: object
                      properties:
                        url:
                          type: string
                        host:
                          type: string
                        port:
                          type: integer
                        database:
                          type: string
                        username:
                          type: string
                        passwordSecret:
                          type: object
                          properties:
                            name:
                              type: string
                            field:
                              type: string
                      oneOf:
                        - required: [ "url" ]
                        - required: [ "host", "database" ]

                    postgres:
                      type: object
                      properties:
                        url:
                          type: string
                        host:
                          type: string
                        port:
                          type: integer
                        database:
                          type: string
                        username:
                          type: string
                        passwordSecret:
                          type: object
                          properties:
                            name:
                              type: string
                            field:
                              type: string
                      oneOf:
                        - required: [ "url" ]
                        - required: [ "host", "database" ]

                    embedded:
                      type: object

            status:
              type: object
              properties:
                phase:
                  type: string
                message:
                  type: string

      subresources:
        status: {}

      additionalPrinterColumns:
        - name: Phase
          type: string
          description: The current phase of the deployment
          jsonPath: .status.phase
        - name: Message
          type: string
          description: Status message
          jsonPath: .status.message
