{{ if .Values.promtail.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: promtail
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
  finalizers:
  - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: loki
    server: 'https://kubernetes.default.svc'
  sources:
  #- repoURL: {{ .Values.cluster_config.manifests }}
  #  path: {{ .Values.cluster_config.policies }}/promtail
  #  targetRevision: HEAD
  - repoURL: 'https://grafana.github.io/helm-charts'
    targetRevision: {{ .Values.promtail.version }}
    chart: promtail
    helm:
      values: |
        config:
          snippets:
            pipelineStages:
            - labelallow:
              - app
              - app_kubernetes_io_component
              - app_kubernetes_io_instance
              - app_kubernetes_io_version
              - container
              - instance
              - namespace
              - pod
              - stream
  project: sys
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: sys
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
    {{- if .Values.promtail.autosync }}
    automated:
      prune: true
      # selfHeal: false
    {{- end }}
{{ end }}
