﻿apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: mobiledevices.kaponata.io
  labels:
    app.kubernetes.io/managed-by: Kaponata
    # Set this to the version number of the last commit which modified this file. It's used by the
    # operator to determine whether the CRD should be reinstalled or not.
    # Use the following command to determine that version:
    # nbgv get-version $(git rev-list -1 HEAD) -v NuGetPackageVersion
    app.kubernetes.io/version: "0.3.348"
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: kaponata.io
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1alpha1
      # 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:
          description: |
            A MobileDevice represents a physical iOS or Android devices connected to one of the nodes
            in your Kubernetes cluster, an emulator running inside your Kubernets cluster, or a
            cloud device which is remotely connected to your cluster.
            The name of the MobileDevice object is the serial number or UDID of the device.
            The kubernetes.io/os an kubernets.io/arch labels contain the operating system (for example,
            iOS or Android) running on the device and the architecture (for example, arm64 or amd64)
            of the device.
          type: object
          properties:
            spec:
              type: object
              properties:
                owner:
                  type: string
                  description: |
                    The name of the pod which owns this device. This is usually the pod which hosts the
                    usbmuxd or adb instance to which the device is connected.
            status:
              type: object
              properties:
                vncHost:
                  type: string
                  description: |
                    When available, the name of a service or IP address of a pod which hosts a VNC server
                    which allows users to remotely control this device.
                vncPassword:
                  type: string
                  format: password
                  description: |
                    When available, a password which can be used to connect to the VNC server at vncHost.
                conditions:
                  description: |
                    Conditions is a list of all conditions this MobileDevice is in.
                  items:
                    description: |
                      MobileDeviceCondition contains details for the current condition of this MobileDevice.
                    properties:
                      type:
                        description: Type of the condition.  The condition type uniquely identifies the condition.
                        type: string
                      status:
                        description: |
                          Status of the condition, one of ('True', 'False', 'Unknown').
                        type: string
                        enum:
                        - 'True'
                        - 'False'
                        - 'Unknown'
                      reason:
                        description: |
                          Reason is the (brief) reason for the condition's last transition.
                        type: string
                      message:
                        description: |
                          Message is the human readable message indicating details about last transition.
                        type: string
                      lastHeartbeatTime:
                        description: |
                          LastHeartbeatTime is the timestamp corresponding to the last update of this condition.
                        format: date-time
                        type: string
                      lastTransitionTime:
                        description: |
                          LastTransitionTime is the last time the device condition transitioned from one status to another.
                        format: date-time
                        type: string
                    required:
                    - status
                    - type
                    type: object
                  type: array

                  # These properties are used by Kubernetes strategic merge operations.  They should allows us to
                  # patch lists (such as status.conditions) by specifying a 'key' (type in this case).
                  # Unfortunately, Kubernetes does not currently support strategy merges for custom resources:
                  # 
                  "x-kubernetes-list-map-keys":
                    - "type"
                  "x-kubernetes-list-type": "map"
            
      # This section enables the 'status' subresource.  It allows controllers to only patch the status stanza
      # by posting to /status.
      subresources:
        status: {}

      # Shown in kubectl get
      additionalPrinterColumns:
      - name: Labels
        type: string
        jsonPath: .metadata.labels
      - name: Owner
        type: string
        jsonPath: .spec.owner
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: mobiledevices
    # singular name to be used as an alias on the CLI and for display
    singular: mobiledevice
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: MobileDevice
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - device
