
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  labels:
    io.shyrka: ""
    io.shyrka.erebus/hypnos: "v1alpha2"
    app: shyrka-erebus
  name: hypnox.shyrkaio.github.io
spec:
  group: shyrkaio.github.io
  names:
    kind: Hypnos
    listKind: HypnosList
    plural: hypnox
    singular: hypnos
  scope: Cluster
  versions:
    - name: v1alpha2
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          #https://swagger.io/docs/specification/data-models/data-types/
          type: object
          properties:
            spec:
              type: object
              properties:
                namespaceTargetedLabel:
                  type: string
                  nullable: false
                  #@TODO pattern: ... or switch to a match selector
                targetedLabel:
                  type: string
                  nullable: true
                  #@TODO pattern: ... or switch to a match selector
                resourceType:
                  type: array
                  nullable: false
                  items:
                    type: string
                    enum: [Deployment, StatefulSet, DeploymentConfig]
                cron-type:
                  type: string
                  enum: [unix, quartz]
                  default: quartz
                wakeup-cron:
                  nullable: false
                  type: string
                  pattern: '(((\d+,)+\d+|(\d+(\/|-)\d+)|\d?|\d+|\*) ?){5,7}'
                  # I wonder if a default is a good idea
                  #default: "5 0 * * *"
                sleep-cron:
                  type: string
                  nullable: false
                  pattern: '(((\d+,)+\d+|(\d+(\/|-)\d+)|\d?|\d+|\*) ?){5,7}'
                  # I wonder if a default is is a good idea
                  #default: "5 0 * * *"
                load-policy: # not-implemented-yet
                  type: string
                  enum: [run-sleep-on-change, run-wake-up-on-change, no-action]
                  default: no-action
                dry-run: # not-implemented-yet
                  type: boolean
                  default: false
                pause: # not-implemented-yet
                  type: boolean #pause: not-implemented-yet
                  default: false
                comments:
                  type: string
                  maxLength: 256
            status:
              type: object
              properties:
                lastRun:
                  type: string
                  format: date-time
                nbtarget:
                  type: integer
      additionalPrinterColumns:
        - name: NameSpace Targeted Label
          type: string
          description: The label used to select targeted namespace
          jsonPath: .spec.namespaceTargetedLabel
        - name: Targeted Label
          type: string
          description: The label used to select resource to touch
          jsonPath: .spec.targetedLabel
        - name: Resource
          type: string
          description: The resource type to be scale up / scale down
          jsonPath: .spec.resourceType
        - name: WakeUp
          type: string
          description: The Cron Definition for the wake-up call
          jsonPath: .spec.wakeup-cron
        - name: Sleep
          type: string
          description: The Cron Definition for the sleep call
          jsonPath: .spec.sleep-cron
        - name: comments
          type: string
          description: some comments on this hypnos definition
          jsonPath: .spec.comments