{{- if .Values.chartmuseum.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: chartmuseum
  namespace: argocd
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: argocd
    server: 'https://kubernetes.default.svc'
  source:
    repoURL: 'https://chartmuseum.github.io/charts'
    targetRevision: {{ .Values.chartmuseum.version }}
    chart: chartmuseum
    helm:
      values: |
        env:
          open:
            ENABLE_METRICS: true
            DISABLE_API: false
            ALLOW_OVERWRITE: false
            CHART_URL: ""
            AUTH_ANONYMOUS_GET: true
          existingSecret: chartmuseum-basic-auth
          existingSecretMappings:
            BASIC_AUTH_USER: user
            BASIC_AUTH_PASS: password
        extraArgs:
          - --web-template-path=/storage/web
        serviceMonitor:
          enabled: false
        persistence:
          enabled: true
          accessMode: ReadWriteOnce
          size: {{ .Values.chartmuseum.storage.size }}
          path: /storage
          storageClass: ""
        ingress:
          enabled: {{ .Values.chartmuseum.ingress.enabled }}
          annotations:
            {{- with .Values.cluster_config.ingress_whitelist_ips}}
            nginx.ingress.kubernetes.io/whitelist-source-range: {{ join "," . }}
            {{- end }}
            cert-manager.io/cluster-issuer: {{ .Values.cluster_config.ingress_clusterissuer }}
          ingressClassName: nginx
          hosts:
            - name: charts.{{ .Values.cluster_config.domain }}
              path: /
              tls: true
              tlsSecret: chartmuseum-tls
  project: sys
  {{- if .Values.chartmuseum.autosync }}
  syncPolicy:
    automated:
      prune: true
      # selfHeal: false
  {{- end }}
{{- end }}
