apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: reports.metering.openshift.io
spec:
  group: metering.openshift.io
  scope: Namespaced
  names:
    plural: reports
    singular: report
    kind: Report
  versions:
  - name: v1
    served: true
    storage: true
    additionalPrinterColumns:
    - name: Query
      type: string
      jsonPath: .spec.query
    - name: Schedule
      type: string
      jsonPath: .spec.schedule.period
    - name: Running
      type: string
      jsonPath: .status.conditions[?(@.type=="Running")].reason
    - name: Failed
      type: string
      jsonPath: .status.conditions[?(@.type=="Failure")].reason
    - name: Last Report Time
      type: string
      jsonPath: .status.lastReportTime
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
    schema:
      openAPIV3Schema:
        type: object
        required:
        - spec
        properties:
          spec:
            type: object
            required:
            - query
            properties:
              query:
                type: string
                minLength: 1
              reportingStart:
                type: string
                format: date-time
              reportingEnd:
                type: string
                format: date-time
              expiration:
                type: string
                format: duration
              runImmediately:
                type: boolean
              overwriteExistingData:
                type: boolean
              inputs:
                type: array
                minItems: 1
                items:
                  type: object
                  required:
                  - name
                  - value
                  properties:
                    name:
                      type: string
                      minLength: 1
                    value:
                      type: string
              schedule:
                type: object
                required:
                - period
                properties:
                  period:
                    type: string
                    minLength: 1
                    enum:
                    - hourly
                    - daily
                    - weekly
                    - monthly
                    - cron
                  hourly:
                    type: object
                    properties:
                      second:
                        type: integer
                        minimum: 0
                        maximum: 60
                      minute:
                        type: integer
                        minimum: 0
                        maximum: 59
                  daily:
                    type: object
                    properties:
                      second:
                        type: integer
                        minimum: 0
                        maximum: 60
                      minute:
                        type: integer
                        minimum: 0
                        maximum: 59
                      hour:
                        type: integer
                        minimum: 0
                        maximum: 23
                  weekly:
                    type: object
                    properties:
                      dayofWeek:
                        type: string
                        enum:
                        - sun
                        - sunday
                        - mon
                        - monday
                        - tue
                        - tues
                        - tuesday
                        - wed
                        - weds
                        - wednesday
                        - thur
                        - thurs
                        - thursday
                        - fri
                        - friday
                        - sat
                        - saturday
                      second:
                        type: integer
                        minimum: 0
                        maximum: 60
                      minute:
                        type: integer
                        minimum: 0
                        maximum: 59
                      hour:
                        type: integer
                        minimum: 0
                        maximum: 23
                      dayOfWeek:
                        type: string
                  monthly:
                    type: object
                    properties:
                      dayOfMonth:
                        type: integer
                        minimum: 1
                        maximum: 31
                      second:
                        type: integer
                        minimum: 0
                        maximum: 60
                      minute:
                        type: integer
                        minimum: 0
                        maximum: 59
                      hour:
                        type: integer
                        minimum: 0
                        maximum: 23
                  cron:
                    type: object
                    required:
                    - expression
                    properties:
                      expression:
                        type: string
                        pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
                oneOf:
                - properties:
                    period:
                      enum:
                      - hourly
                  allOf:
                  - not:
                      required:
                      - daily
                  - not:
                      required:
                      - weekly
                  - not:
                      required:
                      - monthly
                  - not:
                      required:
                      - cron
                - properties:
                    period:
                      enum:
                      - daily
                  allOf:
                  - not:
                      required:
                      - hourly
                  - not:
                      required:
                      - weekly
                  - not:
                      required:
                      - monthly
                  - not:
                      required:
                      - cron
                - properties:
                    period:
                      enum:
                      - weekly
                  allOf:
                  - not:
                      required:
                      - hourly
                  - not:
                      required:
                      - daily
                  - not:
                      required:
                      - monthly
                  - not:
                      required:
                      - cron
                - properties:
                    period:
                      enum:
                      - monthly
                  allOf:
                  - not:
                      required:
                      - hourly
                  - not:
                      required:
                      - daily
                  - not:
                      required:
                      - weekly
                  - not:
                      required:
                      - cron
                - properties:
                    period:
                      enum:
                      - cron
                  allOf:
                  - not:
                      required:
                      - hourly
                  - not:
                      required:
                      - daily
                  - not:
                      required:
                      - weekly
                  - not:
                      required:
                      - monthly
            anyOf:
            # runOnce report
            - required:
              - query
              - reportingStart
              - reportingEnd
            # runImmediately report
            - required:
              - query
              - runImmediately
              - reportingEnd
            # scheduled report
            - required:
              - query
              - schedule
          status:
            type: object
            properties:
              lastReportTime:
                type: string
                format: date-time
              nextReportTime:
                type: string
                format: date-time
              tableRef:
                type: object
                properties:
                  name:
                    type: string
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    reason:
                      type: string
                    message:
                      type: string
                    lastUpdateTime:
                      type: string
                      format: date-time
                    lastTransitionTime:
                      type: string
                      format: date-time
                    status:
                      type: string
                      enum:
                      - "True"
                      - "False"
                      - "Unknown"
