{{- if .Values.crd.create }}
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: canaries.flagger.app
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:
            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
            service:
              type: object
              required: ['port']
              properties:
                port:
                  type: number
            canaryAnalysis:
              properties:
                interval:
                  type: string
                  pattern: "^[0-9]+(m|s)"
                threshold:
                  type: number
                maxWeight:
                  type: number
                stepWeight:
                  type: number
                metrics:
                  type: array
                  properties:
                    items:
                      type: object
                      required: ['name', 'interval', 'threshold']
                      properties:
                        name:
                          type: string
                        interval:
                          type: string
                          pattern: "^[0-9]+(m|s)"
                        threshold:
                          type: number
                webhooks:
                  type: array
                  properties:
                    items:
                      type: object
                      required: ['name', 'url', 'timeout']
                      properties:
                        name:
                          type: string
                        url:
                          type: string
                          format: url
                        timeout:
                          type: string
                          pattern: "^[0-9]+(m|s)"
{{- end }}
