apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
  name: operational
spec:
  image: {{ template "imageRegistry" . -}} {{ .Values.postgresCluster.image.name }}:{{ .Values.postgresCluster.image.version }}
  postgresVersion: {{ .Values.postgresCluster.postgresVersion }}
  databaseInitSQL:
    key: init.sql
    name: rm-template-stat-statements
  instances:
    - name: {{ .Values.global.crunchyPostgresOperator.instances.operational.name }}
      replicas: {{ .Values.global.crunchyPostgresOperator.instances.operational.replicas }}
      metadata:
        annotations:
          backup.velero.io/backup-volumes: postgres-data
        labels:
          collect.logs: "plain-text"
      dataVolumeClaimSpec:
        storageClassName: {{ .Values.global.storageClass }}
        accessModes:
        - "ReadWriteOnce"
        resources:
          requests:
            storage: {{ .Values.global.crunchyPostgres.storageSize }}
  backups:
     pgbackrest:
       image: {{ template "imageRegistry" . -}} {{ .Values.postgresCluster.pgbackrest.image.name }}:{{ .Values.postgresCluster.pgbackrest.image.version }}
       metadata:
         labels:
           collect.logs: "plain-text"
       configuration:
       - secret:
           name: {{ .Values.postgresCluster.minioSecretName }}
       global:
         repo1-path: "/postgres-backup/{{ .Values.namespace }}/operational"
         {{- with .Values.postgresCluster.backups.pgbackrest.global }}
         {{- toYaml . | nindent 9 }}
         {{- end }}
       repos:
       - name: {{ .Values.postgresCluster.backups.pgbackrest.repos.name }}
         schedules:
           full: "{{ .Values.global.crunchyPostgres.backups.pgbackrest.repos.schedules.full }}"
         s3:
           bucket: {{ .Values.global.crunchyPostgresOperator.minioConf.bucketName }}
           endpoint: {{ .Values.global.crunchyPostgresOperator.minioConf.endpoint }}
           region: {{ .Values.postgresCluster.region }}
  patroni:
    dynamicConfiguration:
      failsafe_mode: true
      synchronous_mode: true
      synchronous_node_count: {{ sub .Values.global.crunchyPostgresOperator.instances.operational.replicas 1 }}
      pause: false
      postgresql:
      {{- with .Values.postgresCluster.postgresql.parameters }}
        parameters:
          max_connections: {{ $.Values.global.crunchyPostgres.postgresql.parameters.max_connections }}
      {{- toYaml . | nindent 10 }}
      {{- end }}
        pg_hba:
          - host all all all md5
        use_slots: true
      slots:
        operational_sub:
          database: registry
          plugin: pgoutput
          type: logical
  users:
    - name: postgres
      password:
        type: AlphaNumeric
  monitoring:
    pgmonitor:
      exporter:
        image: {{ template "imageRegistry" . -}} {{ .Values.postgresCluster.pgmonitor.exporter.image.name }}:{{ .Values.postgresCluster.pgmonitor.exporter.image.version }}
---
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
  name: analytical
spec:
  image: {{ template "imageRegistry" . -}} {{ .Values.postgresCluster.image.name }}:{{ .Values.postgresCluster.image.version }}
  postgresVersion: {{ .Values.postgresCluster.postgresVersion }}
  databaseInitSQL:
    key: init.sql
    name: rm-template-stat-statements
  instances:
    - name: {{ .Values.global.crunchyPostgresOperator.instances.analytical.name }}
      replicas: {{ .Values.global.crunchyPostgresOperator.instances.analytical.replicas }}
      metadata:
        annotations:
          backup.velero.io/backup-volumes: postgres-data
        labels:
          collect.logs: "plain-text"
      dataVolumeClaimSpec:
        storageClassName: {{ .Values.global.storageClass }}
        accessModes:
        - "ReadWriteOnce"
        resources:
          requests:
            storage: {{ .Values.global.crunchyPostgres.storageSize }}
  backups:
     pgbackrest:
       image: {{ template "imageRegistry" . -}} {{ .Values.postgresCluster.pgbackrest.image.name }}:{{ .Values.postgresCluster.pgbackrest.image.version }}
       metadata:
         labels:
           collect.logs: "plain-text"
       configuration:
       - secret:
           name: {{ .Values.postgresCluster.minioSecretName }}
       global:
         repo1-path: "/postgres-backup/{{ .Values.namespace }}/analytical"
         {{- with .Values.postgresCluster.backups.pgbackrest.global }}
         {{- toYaml . | nindent 9 }}
         {{- end }}
       repos:
       - name: {{ .Values.postgresCluster.backups.pgbackrest.repos.name }}
         schedules:
           full: "{{ .Values.global.crunchyPostgres.backups.pgbackrest.repos.schedules.full }}"
         s3:
           bucket: {{ .Values.global.crunchyPostgresOperator.minioConf.bucketName }}
           endpoint: {{ .Values.global.crunchyPostgresOperator.minioConf.endpoint }}
           region: {{ .Values.postgresCluster.region }}
  patroni:
    dynamicConfiguration:
      failsafe_mode: true
      synchronous_mode: true
      synchronous_node_count: {{ sub .Values.global.crunchyPostgresOperator.instances.analytical.replicas 1 }}
      pause: false
      postgresql:
      {{- with .Values.postgresCluster.postgresql.parameters }}
        parameters:
          max_connections: {{ $.Values.global.crunchyPostgres.postgresql.parameters.max_connections }}
      {{- toYaml . | nindent 10 }}
      {{- end }}
        pg_hba:
          - host all all all md5
        use_slots: true
  users:
    - name: postgres
      password:
        type: AlphaNumeric
  monitoring:
    pgmonitor:
      exporter:
        image: {{ template "imageRegistry" . -}} {{ .Values.postgresCluster.pgmonitor.exporter.image.name }}:{{ .Values.postgresCluster.pgmonitor.exporter.image.version }}
