{{- $fullname := include "vCluster.fullname" . -}}
{{- $name := include "vCluster.releaseName" . -}}
{{- if .Values.persistence }}
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: {{ $fullname }}-db
  namespace: {{ .Release.Namespace }}
  annotations:
    linkerd.io/inject: disabled
spec:
  instances: 1
  bootstrap:
    initdb:
      database: k3s
      owner: k3s
  primaryUpdateStrategy: unsupervised
  backup:
    retentionPolicy: "7d"
  storage:
    size: "5Gi"
{{- end }}
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: {{ $name }}-archmaester
  namespace: {{ .Release.Namespace }}
  annotations:
    linkerd.io/inject: disabled
spec:
  instances: 1
  imageName: ghcr.io/cloudnative-pg/postgis:15-3.3
  bootstrap:
    initdb:
      postInitTemplateSQL:
      - CREATE EXTENSION postgis;
      - CREATE EXTENSION postgis_topology;
      - CREATE EXTENSION fuzzystrmatch;
      - CREATE EXTENSION postgis_tiger_geocoder;
  # Example of rolling update strategy:
  # - unsupervised: automated update of the primary once all
  #                 replicas have been upgraded (default)
  # - supervised: requires manual supervision to perform
  #               the switchover of the primary
  primaryUpdateStrategy: unsupervised
  backup:
    retentionPolicy: "7d"
  storage:
    size: "5Gi"
  bootstrap:
    pg_basebackup:
      source: prod-archmeister
  externalClusters:
  - name: prod-archmeister
    connectionParameters:
      host: prod-archmeister-rw.atlantis
      user: streaming_replica
      sslmode: verify-full
    sslKey:
      name: prod-archmeister-replication
      key: tls.key
    sslCert:
      name: prod-archmeister-replication
      key: tls.crt
    sslRootCert:
      name: prod-archmeister-ca
      key: ca.crt

