apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: canaries.flagger.app
  annotations:
    helm.sh/resource-policy: keep
spec:
  group: flagger.app
  version: v1alpha3
  versions:
    - name: v1alpha3
      served: true
      storage: true
    - name: v1alpha2
      served: true
      storage: false
    - name: v1alpha1
      served: true
      storage: false
  names:
    plural: canaries
    singular: canary
    kind: Canary
    categories:
      - all
  scope: Namespaced
  subresources:
    status: {}
  additionalPrinterColumns:
    - name: Status
      type: string
      JSONPath: .status.phase
    - name: Weight
      type: string
      JSONPath: .status.canaryWeight
    - name: LastTransitionTime
      type: string
      JSONPath: .status.lastTransitionTime
  validation:
    openAPIV3Schema:
      properties:
        spec:
          required:
            - targetRef
            - service
            - canaryAnalysis
          properties:
            provider:
              type: string
            progressDeadlineSeconds:
              type: number
            targetRef:
              type: object
              required: ['apiVersion', 'kind', 'name']
              properties:
                apiVersion:
                  type: string
                kind:
                  type: string
                name:
                  type: string
            autoscalerRef:
              anyOf:
                - type: string
                - type: object
              required: ['apiVersion', 'kind', 'name']
              properties:
                apiVersion:
                  type: string
                kind:
                  type: string
                name:
                  type: string
            ingressRef:
              anyOf:
                - type: string
                - type: object
              required: ['apiVersion', 'kind', 'name']
              properties:
                apiVersion:
                  type: string
                kind:
                  type: string
                name:
                  type: string
            service:
              type: object
              required: ['port']
              properties:
                port:
                  type: number
                portName:
                  type: string
                portDiscovery:
                  type: boolean
                meshName:
                  type: string
                timeout:
                  type: string
            skipAnalysis:
              type: boolean
            canaryAnalysis:
              properties:
                interval:
                  description: Canary schedule interval
                  type: string
                  pattern: "^[0-9]+(m|s)"
                iterations:
                  description: Number of checks to run for A/B Testing and Blue/Green
                  type: number
                threshold:
                  description: Max number of failed checks before rollback
                  type: number
                maxWeight:
                  description: Max traffic percentage routed to canary
                  type: number
                stepWeight:
                  description: Canary incremental traffic percentage step
                  type: number
                metrics:
                  description: Prometheus query list for this canary
                  type: array
                  properties:
                    items:
                      type: object
                      required: ['name', 'threshold']
                      properties:
                        name:
                          description: Name of the Prometheus metric
                          type: string
                        interval:
                          description: Interval of the promql query
                          type: string
                          pattern: "^[0-9]+(m|s)"
                        threshold:
                          description: Max scalar value accepted for this metric
                          type: number
                        query:
                          description: Prometheus query
                          type: string
                webhooks:
                  description: Webhook list for this canary
                  type: array
                  properties:
                    items:
                      type: object
                      required: ['name', 'url', 'timeout']
                      properties:
                        name:
                          description: Name of the webhook
                          type: string
                        type:
                          description: Type of the webhook pre, post or during rollout
                          type: string
                          enum:
                            - ""
                            - pre-rollout
                            - rollout
                            - post-rollout
                        url:
                          description: URL address of this webhook
                          type: string
                          format: url
                        timeout:
                          description: Request timeout for this webhook
                          type: string
                          pattern: "^[0-9]+(m|s)"
        status:
          properties:
            phase:
              description: Analysis phase of this canary
              type: string
              enum:
                - ""
                - Initializing
                - Initialized
                - Waiting
                - Progressing
                - Finalising
                - Succeeded
                - Failed
            canaryWeight:
              description: Traffic weight percentage routed to canary
              type: number
            failedChecks:
              description: Failed check count of the current canary analysis
              type: number
            iterations:
              description: Iteration count of the current canary analysis
              type: number
            lastAppliedSpec:
              description: LastAppliedSpec of this canary
              type: string
            lastTransitionTime:
              description: LastTransitionTime of this canary
              format: date-time
              type: string
            conditions:
              description: Status conditions of this canary
              type: array
              properties:
                items:
                  type: object
                  required: ['type', 'status', 'reason']
                  properties:
                    lastTransitionTime:
                      description: LastTransitionTime of this condition
                      format: date-time
                      type: string
                    lastUpdateTime:
                      description: LastUpdateTime of this condition
                      format: date-time
                      type: string
                    message:
                      description: Message associated with this condition
                      type: string
                    reason:
                      description: Reason for the current status of this condition
                      type: string
                    status:
                      description: Status of this condition
                      type: string
                    type:
                      description: Type of this condition
                      type: string
