{{- if .Values.argo_workflows.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: argo-workflows
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "-1"
spec:
  destination:
    namespace: argocd
    server: 'https://kubernetes.default.svc'
  sources:
  - repoURL: 'https://argoproj.github.io/argo-helm'
    targetRevision: {{ .Values.argo_workflows.version }}
    chart: argo-workflows
    helm:
      values: |
        controller:
          workflowNamespaces:
          {{- .Values.argo_workflows.allowed_namespaces | toYaml  | nindent 10 }}
          {{- with .Values.argo_workflows.metrics.enabled }}
          metricsConfig:
            enabled: true
          serviceMonitor:
            enabled: true
          {{- end }}
        server:
          extraArgs:
          - --auth-mode=server
        workflow:
          rbac:
            create: true
          serviceAccount:
            create: true
            name: argo-workflow
  project: argo-workflows
  {{- if .Values.argo_workflows.autosync }}
  syncPolicy:
    automated:
      prune: true
  {{- end }}
{{- end }}
