apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: globaltrafficpolicies.citrix.com
spec:
  group: citrix.com
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: globaltrafficpolicies
    # singular name to be used as an alias on the CLI and for display
    singular: globaltrafficpolicy
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: globaltrafficpolicy
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - gtp
  versions: 
  - name: v1beta1
    served: true
    storage: true
    subresources:
      status: {}
    additionalPrinterColumns:
      - name: Status
        type: string
        description: "Current Status of the CRD"
        jsonPath: .status.state
      - name: Message
        type: string
        description: "Status Message"
        jsonPath: .status.status_message 
    schema:
     # openAPIV3Schema is the schema for validating custom objects.
      openAPIV3Schema:
        type: object
        required: ["apiVersion","kind","metadata","spec"]
        properties:
          apiVersion:
            type: string
          kind:
            type: string
          metadata:
            #required: ["name","namespace"]
            properties:
              name:
                type: string
              #namespace:
              #  type: string
            type: object
          status:
            type: object
            properties:
              state:
                 type: string
              status_message:
                 type: string
          spec:
            required: ["serviceType","hosts","status"]
            properties:
              ipType:
                type: string
                enum:
                - ipv4
                description: "Type of address A or AAAA. Currently only A is supported"
              serviceType:
                type: string
                enum:
                - HTTP
                - SSL
                - TCP
                - UDP
                - ANY
                description: "Protocol supported in multi-cluster deployment"
              hosts:
                items:
                  required: ["host","policy"]
                  properties:
                    host:
                      type: string
                      description: "Domain for which multi-cluster support will be applied"
                    policy:
                      required: ["targets","trafficPolicy"]
                      properties:
                        trafficPolicy:
                          type: string
                          enum:
                          - LOCAL-FIRST
                          - CANARY
                          - FAILOVER
                          - RTT
                          - ROUNDROBIN
                          - STATICPROXIMITY
                          description: "The traffic distribution policy supported in multi-cluster deployment"
                        secLbMethod:
                          type: string
                          description: "The traffic distribution policy supported among clusters under a group in local-first, canary or failover"
                        targets:
                          items:
                            required: ["destination"]
                            properties:
                              destination:
                                type: string
                                description: "Ingress or LoadBalancer service endpoint in each cluster"
                              weight:
                                type: integer
                                minimum: 0 
                                maximum: 100
                                description: "Proportion of traffic to be maintained across clusters. For canary proportion is percentage"
                              rule: 
                                type: string
                              CIDR:
                                type: string
                                description: "CIDR to be used in local-first to determine the scope of locality"
                              primary:
                                type: boolean
                                description: "Is this destination a primary cluster or a backup cluster in failover deployment. Possible values: True or False"
                            type: object
                          type: array
                        monitor:
                          items:
                            properties:
                              monType: 
                                type: string
                                enum:
                                - PING
                                - TCP
                                - HTTP
                                - HTTPS
                                - ping
                                - tcp
                                - http
                                - https
                                description: "Type of probe to determine the health of multi-cluster endpoint"
                              uri:
                                type: string
                                description: "Path to be probed for the health of multi-cluster endpoint in case of http and https"
                              respCode:
                                type: integer
                                description: "Response code expected to mark the multi-cluster endpoint healthy in case of http and https"
                            type: object
                          type: array
                      type: object
                  type: object
                type: array
              status:
                type: object
            type: object
