- name: argo-cd
  namespace: cicd
  create_namespace: true
  chart_ref: {{ .Modules.Cicd.ArgoCd.ChartRef }}
  chart_version: {{ .Modules.Cicd.ArgoCd.ChartVersion }}
  {{- if .Modules.Cicd.Enabled }}
  release_state: "present"
  {{- else }}
  release_state: "absent"
  {{- end }}
  values:
    crds:
      install: true

    global:
      repository: {{ .Modules.Cicd.ArgoCd.Global.Image }}
      tag: {{ .Modules.Cicd.ArgoCd.Global.Tag }}

    server:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.Server.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.Server.Tag }}
      certificateSecret:
        enabled: false
      {{- if eq .Modules.Cicd.ArgoCd.Expose.Type "NodePort" }}
      service:
        type: "NodePort"
        nodePortHttp: {{ .Modules.Cicd.ArgoCd.Expose.NodePortHttp }}
        nodePortHttps: {{ .Modules.Cicd.ArgoCd.Expose.NodePortHttps }}
      {{- end }}
      {{- if .Modules.Cicd.ArgoCd.Ha.Enabled }}
      {{- if .Modules.Cicd.ArgoCd.Ha.Autoscaling }}
      autoscaling:
        enabled: true
        minReplicas: 2
      {{- else }}
      replicas: 2
      {{- end }}
      {{- end }}

      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        serviceMonitor:
          enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}

    redis:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.Redis.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.Redis.Tag }}
      exporter:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        image:
          repository: {{ .Modules.Cicd.ArgoCd.Redis.Exporter.Image }}
          tag: {{ .Modules.Cicd.ArgoCd.Redis.Exporter.Tag }}
      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        serviceMonitor:
          enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}

    controller:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.Controller.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.Controller.Tag }}
      replicas: 1
      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        serviceMonitor:
          enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}

    applicationSet:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.ApplicationSet.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.ApplicationSet.Tag }}
      {{- if .Modules.Cicd.ArgoCd.Ha.Enabled }}
      replicas: 2
      {{- end }}
      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        serviceMonitor:
          enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}

    dex:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.Dex.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.Dex.Tag }}
      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        ## check later
        serviceMonitor:
          enabled: false

    repoServer:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.RepoServer.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.RepoServer.Tag }}
      {{- if .Modules.Cicd.ArgoCd.Ha.Enabled }}
      {{- if .Modules.Cicd.ArgoCd.Ha.Autoscaling }}
      autoscaling:
        enabled: true
        minReplicas: 2
      {{- else }}
      replicas: 2
      {{- end }}
      {{- end }}
      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        serviceMonitor:
          enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}

    notifications:
      image:
        repository: {{ .Modules.Cicd.ArgoCd.Notifications.Image }}
        tag: {{ .Modules.Cicd.ArgoCd.Notifications.Tag }}
      metrics:
        enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}
        serviceMonitor:
          enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Monitoring.Enabled }}

    configs:
      params:
        server.insecure: true
        {{- if not (eq .Modules.Cicd.ArgoCd.Expose.Path "/" ) }}
        server.rootpath: '{{ .Modules.Cicd.ArgoCd.Expose.Path }}'
        {{- end }}

      secret:
        argocdServerAdminPassword: {{ .Modules.Cicd.ArgoCd.AdminPassword }}

      repositories:
        # add default helm-repository from harbor
        {{- .Modules.Cicd.ArgoCd.Repositories | toYaml | nindent 8 }}

      cm:
        create: true
        url: "{{ if .Modules.Cicd.ArgoCd.Expose.Tls.Enabled }}https{{ else }}http{{ end }}://{{ .Modules.Cicd.ArgoCd.Expose.Domain }}"

        accounts.developer: login
        accounts.guest: login

        # oidc.config: ""

      rbac:
        create: true
        policy.csv: |
          p, role:admin, applications, create, */*, allow
          p, role:admin, applications, update, */*, allow
          p, role:admin, applications, delete, */*, allow
          p, role:admin, applications, sync, */*, allow
          p, role:admin, applications, override, */*, allow
          p, role:admin, applications, action/*, */*, allow
          p, role:admin, applicationsets, get, */*, allow
          p, role:admin, applicationsets, create, */*, allow
          p, role:admin, applicationsets, update, */*, allow
          p, role:admin, applicationsets, delete, */*, allow
          p, role:admin, certificates, create, *, allow
          p, role:admin, certificates, update, *, allow
          p, role:admin, certificates, delete, *, allow
          p, role:admin, clusters, create, *, allow
          p, role:admin, clusters, update, *, allow
          p, role:admin, clusters, delete, *, allow
          p, role:admin, repositories, create, *, allow
          p, role:admin, repositories, update, *, allow
          p, role:admin, repositories, delete, *, allow
          p, role:admin, projects, create, *, allow
          p, role:admin, projects, update, *, allow
          p, role:admin, projects, delete, *, allow
          p, role:admin, accounts, update, *, allow
          p, role:admin, gpgkeys, create, *, allow
          p, role:admin, gpgkeys, delete, *, allow
          p, role:admin, exec, create, */*, allow

          {{- .Modules.Cicd.ArgoCd.Rbac.AdditionalPolicies }}


        policy.default: role:''
        # scopes: "[roles,email,groups]"

    {{- if .Modules.Cicd.ArgoCd.Ha.Enabled }}
    redis-ha:
      enabled: true
    {{- end }}
