#@ load("@ytt:data", "data")

#@ ns = data.values.application.namespace

---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: forgejo-cnpg
  namespace: #@ ns
spec:
  instances: 2

  bootstrap:
    initdb:
      database: forgejo
      owner: forgejo

  storage:
    size: 5Gi
    storageClass: #@ data.values.cluster.storageClass.block

  resources:
    requests:
      cpu: 100m
      memory: 256Mi
    limits:
      memory: 512Mi

  #@ if data.values.backups.enabled:
  backup:
    barmanObjectStore:
      endpointURL: #@ data.values.backups.s3.endpoint
      destinationPath: #@ "s3://{}/forgejo/cnpg".format(data.values.forgejo.backup.s3Bucket)
      s3Credentials:
        accessKeyId:
          name: forgejo-backup-s3
          key: ACCESS_KEY_ID
        secretAccessKey:
          name: forgejo-backup-s3
          key: SECRET_ACCESS_KEY
      wal:
        compression: gzip
      data:
        compression: gzip
    retentionPolicy: "30d"
    target: prefer-standby
  #@ end

  postgresql:
    parameters:
      shared_buffers: "64MB"
      effective_cache_size: "128MB"
      work_mem: "4MB"
      maintenance_work_mem: "32MB"
      max_connections: "50"
