{{- if .Values.crds.install }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: containerregistries.freeleaps.com
  labels:
    {{- include "freeleaps-devops-reconciler.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "-5"
    {{- if .Values.crds.keep }}
    "helm.sh/resource-policy": keep
    {{- end }}
spec:
  group: freeleaps.com
  scope: Namespaced
  names:
    kind: ContainerRegistry
    listKind: ContainerRegistryList
    singular: containerregistry
    plural: containerregistries
    shortNames:
      - registry
      - reg
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          required: ['spec']
          properties:
            spec:
              type: object
              required:
                - projectId
                - registryUrl
                - project
              properties:
                projectId:
                  type: string
                  description: "Reference to DevOpsProject ID"
                registryUrl:
                  type: string
                  description: "Container registry URL"
                project:
                  type: string
                  description: "Registry project/namespace"
                credentialsRef:
                  type: object
                  required:
                    - name
                  properties:
                    name:
                      type: string
                      description: "Secret name containing registry credentials"
                    namespace:
                      type: string
                      description: "Secret namespace"
                repositories:
                  type: array
                  items:
                    type: object
                    required:
                      - name
                    properties:
                      name:
                        type: string
                        description: "Repository name"
                      description:
                        type: string
                        description: "Repository description"
                      public:
                        type: boolean
                        default: false
            status:
              type: object
              properties:
                containerRegistry:
                  type: object
                  properties:
                    status:
                      type: string
                      enum: ["invalid", "valid", "synced"]
                    synced:
                      type: boolean
                    ready:
                      type: boolean
                    lastProbeTime:
                      type: string
                      format: date-time
                    repositories:
                      type: array
                      items:
                        type: object
                        properties:
                          name:
                            type: string
                          url:
                            type: string
                          created:
                            type: boolean
      subresources:
        status: {}
      additionalPrinterColumns:
        - name: Project ID
          type: string
          jsonPath: .spec.projectId
        - name: Registry URL
          type: string
          jsonPath: .spec.registryUrl
        - name: Project
          type: string
          jsonPath: .spec.project
        - name: Status
          type: string
          jsonPath: .status.containerRegistry.status
        - name: Ready
          type: boolean
          jsonPath: .status.containerRegistry.ready
        - name: Age
          type: date
          jsonPath: .metadata.creationTimestamp
{{- end }}