{{- if .Values.crds.install }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: gitcredentials.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: GitCredentials
    listKind: GitCredentialsList
    singular: gitcredentials
    plural: gitcredentials
    shortNames:
      - gitcred
      - gc
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          required: ['spec']
          properties:
            spec:
              type: object
              required:
                - gitUrl
                - credentialsRef
              properties:
                gitUrl:
                  type: string
                  description: "Git repository URL or domain"
                credentialsRef:
                  type: object
                  required:
                    - name
                  properties:
                    name:
                      type: string
                      description: "Secret name containing git credentials"
                    namespace:
                      type: string
                      description: "Secret namespace"
                credentialsId:
                  type: string
                  description: "Jenkins credentials ID to create/update"
                description:
                  type: string
                  description: "Description for the credentials"
            status:
              type: object
              properties:
                gitCredentials:
                  type: object
                  properties:
                    status:
                      type: string
                      enum: ["invalid", "valid", "synced"]
                    synced:
                      type: boolean
                    ready:
                      type: boolean
                    lastProbeTime:
                      type: string
                      format: date-time
                    jenkinsCredentialsId:
                      type: string
                      description: "Created Jenkins credentials ID"
      subresources:
        status: {}
      additionalPrinterColumns:
        - name: Git URL
          type: string
          jsonPath: .spec.gitUrl
        - name: Credentials ID
          type: string
          jsonPath: .status.gitCredentials.jenkinsCredentialsId
        - name: Status
          type: string
          jsonPath: .status.gitCredentials.status
        - name: Ready
          type: boolean
          jsonPath: .status.gitCredentials.ready
        - name: Age
          type: date
          jsonPath: .metadata.creationTimestamp
{{- end }}