apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: reportqueries.metering.openshift.io
spec:
  group: metering.openshift.io
  version: v1
  versions:
  - name: v1
    served: true
    storage: true
  - name: v1alpha1
    served: true
    storage: false
  scope: Namespaced
  names:
    plural: reportqueries
    singular: reportquery
    kind: ReportQuery
    shortNames:
    - rq
  additionalPrinterColumns:
  - name: Age
    type: date
    JSONPath: .metadata.creationTimestamp

  validation:
    openAPIV3Schema:
      type: object
      required:
      - spec
      properties:
        spec:
          type: object
          required:
          - columns
          - query
          properties:
            columns:
              type: array
              minItems: 1
              items:
                type: object
                required:
                - name
                - type
                properties:
                  name:
                    type: string
                    minLength: 1
                  type:
                    type: string
                    enum:
                      - BOOLEAN
                      - TINYINT
                      - SMALLINT
                      - INTEGER
                      - BIGINT
                      - REAL
                      - DOUBLE
                      - DECIMAL
                      - VARCHAR
                      - CHAR
                      - VARBINARY
                      - JSON
                      - DATE
                      - TIME
                      - TIMESTAMP
                      - ARRAY
                      - MAP
                      - MAP<VARCHAR, VARCHAR>
                      - MAP<VARCHAR, INT>
                      - MAP<INT, INT>
                      - MAP<INT, VARCHAR>
                      - ROW
                      - IPADDRESS
                      - UUID
                      - HYPERLOGLOG
                      - P4HYPERLOGLOG
                      - QDIGEST
                      - boolean
                      - tinyint
                      - smallint
                      - integer
                      - bigint
                      - real
                      - double
                      - decimal
                      - varchar
                      - char
                      - varbinary
                      - json
                      - date
                      - time
                      - timestamp
                      - array
                      - map
                      - map<varchar, varchar>
                      - map<varchar, int>
                      - map<int, int>
                      - map<int, varchar>
                      - row
                      - ipaddress
                      - uuid
                      - hyperloglog
                      - p4hyperloglog
                      - qdigest
                  unit:
                    type: string
                    enum:
                      - date
                      - kubernetes_pod
                      - kubernetes_persistentvolumeclaim
                      - kubernetes_persistentvolume
                      - kubernetes_storageclass
                      - kubernetes_namespace
                      - kubernetes_node
                      - bytes
                      - byte_seconds
                      - time
                      - cpu_core_seconds
                      - cpu_cores
                      - memory_bytes
                      - memory_byte_seconds
                      - seconds
                  tableHidden:
                    type: boolean
            inputs:
              type: array
              minItems: 1
              items:
                type: object
                required:
                - name
                properties:
                  name:
                    type: string
                    minLength: 1
                  type:
                    type: string
                    enum:
                      - string
                      - integer
                      - time
                      - ReportDataSource
                      - ReportQuery
                      - Report
                  required:
                    type: boolean
                  default: {}
            query:
              type: string
              pattern: '[Ss][Ee][Ll][Ee][Cc][Tt]\s'
              minLength: 1

