apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: agentic-os-pg
  namespace: platform-data
  labels:
    agentic-os.io/layer: data
    agentic-os.io/component: postgres
spec:
  # 3 instances = 1 primary + 2 replicas (HA)
  instances: 3
  # Supervised update: requires manual promotion approval — protects against accidental failover during maintenance
  primaryUpdateStrategy: supervised
  postgresql:
    parameters:
      max_connections: "200"
      shared_buffers: "256MB"
  storage:
    size: 20Gi
    storageClass: longhorn
  bootstrap:
    initdb:
      database: agentic_os
      owner: agentic_os
  # Continuous WAL archival to MinIO for PITR and disaster recovery
  backup:
    retentionPolicy: "7d"
    barmanObjectStore:
      destinationPath: "s3://cnpg-backups/agentic-os-pg/"
      endpointURL: "http://minio.platform-data.svc.cluster.local:9000"
      s3Credentials:
        accessKeyId:
          name: cnpg-backup-s3-creds
          key: ACCESS_KEY_ID
        secretAccessKey:
          name: cnpg-backup-s3-creds
          key: ACCESS_KEY_SECRET
