{{- if .Values.plausible.enabled }}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: plausible-analytics
  namespace: argocd
spec:
  destination:
    namespace: plausible
    server: 'https://kubernetes.default.svc'
  sources:
  - repoURL: 'https://imio.github.io/helm-charts'
    targetRevision: 0.4.0
    chart: plausible-analytics
    helm:
      values: |
        baseURL: https://plausible.adm.oceanbox.io
        databaseURL: postgres://app:password@plausible-db-rw:5432/app
        clickhouse:
          resources:
            requests:
              cpu: 500m
              ephemeral-storage: 50Mi
              memory: 512Mi
        postgresql:
          enabled: false
        ingress:
          enabled: true
          ingressClassName: nginx
          annotations:
            cert-manager.io/cluster-issuer: letsencrypt-production
            nginx.ingress.kubernetes.io/ssl-redirect: "true"
            nginx.ingress.kubernetes.io/whitelist-source-range: 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,172.19.255.0/24,148.122.135.23
          hosts:
            - plausible.adm.oceanbox.io
          paths:
          - /
          pathType: ImplementationSpecific
          tls:
          - secretName: plausible-tls
            hosts:
            - plausible.adm.oceanbox.io
  project: aux
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        component: aux
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
    automated:
      prune: true
      selfHeal: true
  ignoreDifferences:
    - kind: Secret
      name: plausible-analytics
      jqPathExpressions:
        - '.data'
        - '.metadata.labels'
        - '.metadata.annotations'
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: plausible-db
  namespace: plausible
spec:
  imageName: ghcr.io/cloudnative-pg/postgresql:16.3
  primaryUpdateStrategy: unsupervised
  instances: 1
  monitoring:
    enablePodMonitor: true
  storage:
    size: 10Gi
{{- end }}
