﻿apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: webdriversessions.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.25"
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 WebDriverSession object represents a WebDriver session which is currently running on
            a Kaponata device. It is typically created by a request to the Kaponata API server. An
            operator then picks up the session request and setting up the infrastructure to host
            the session.
          type: object
          properties:
            spec:
              type: object
              properties:
                capabilities:
                  description: |
                    The capabilities requested by the client. This is the value of the "capabilities"
                    element in the new session request, serialized as a string. This object should
                    at least include an "alwaysMatch" property.
                  type: string
                deviceHost:
                  description: The name or IP address at which the device can be reached.
                  type: string
            status:
              type: object
              properties:
                # NOTE:
                # The first set of fields (sessionId, capabilities, error, message, stackTrace and data)
                # are specific to the WebDriver protocol; the other fields are specific to how Kaponata
                # provisions sessions.
                # It may make sense break the 'status' value into two separate objects, one WebDriver
                # specific, and the other Kubernetes specific.

                # WebDriver status fields when session created successfully; see
                # https://www.w3.org/TR/webdriver/#new-session (step 11)
                sessionId:
                  description: The session ID used to uniquely identify the WebDriver session.
                  type: string
                capabilities:
                  description: The session capabilities, as determined by the server.
                  type: string

                # WebDriver status fields when session creation failed; see
                # https://www.w3.org/TR/webdriver/#errors
                error:
                  description: A string indicating the error code.
                  type: string

                message:
                  description: An implementation-defined string with a human readable description of the kind of error that occurred.
                  type: string

                stacktrace:
                  description: An implementation-defined string with a stack trace report of the active stack frames at the time when the error occurred.
                  type: string

                data:
                  description: Additional error data helpful in diagnosing the error.
                  type: string

                # A detailed description of the status of the various components which are provisioned when a session is
                # being created.
                sessionReady:
                  description: A value indicating whether the session is ready on the back-end pod.
                  type: boolean
                sessionPort:
                  description: The TCP port number at which the Appium server is listening.
                  type: integer

                ingressReady:
                  description: A value indicating whether the ingress rules are ready.
                  type: boolean
                serviceReady:
                  description: A value indicating whether the service is ready.
                  type: boolean

      # Shown in kubectl get
      additionalPrinterColumns:
      - name: URL
        type: string
        jsonPath: .status.url
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: webdriversessions
    # singular name to be used as an alias on the CLI and for display
    singular: webdriversession
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: WebDriverSession
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - session