apiVersion: service.aep.asag.io/v1
kind: Definition
metadata:
  name: psql-0.2.1
  namespace: asag
spec:
  clusters:
    - flags:
        - from: value
          key: v1_role
          to: label
          value: postgres
        - from: value
          key: delay_final_config
          to: annotation
          value: true
      name: psql
      nodes:
        flags:
          - from: setting
            key: v1_is_master
            setting: is_master
            to: label
          - from: setting
            key: v1_disable_backup
            setting: disable_backup
            to: label
        settings:
          - from:
              - user
            name: is_master
            schema:
              default: false
              description: Set this node as master
              type: boolean
          - from:
              - user
            name: disable_backup
            schema:
              default: true
              description: Disable backup on this node. Set this to false for at least one node (preferrably slave).
              type: boolean
      podspec:
        containers:
          - image: aep/base_jammy
            name: psql
      provides:
        - exposed: true
          filter:
            - key: v1_is_master
              value: true
          name: psql-rw
          network: loadbalanced
          servicespec:
            ports:
              - name: postgresql
                port: 5432
                protocol: TCP
                targetPort: 5432
        - exposed: true
          filter:
            - key: v1_is_master
              value: false
          name: psql-ro
          network: loadbalanced
          servicespec:
            ports:
              - name: postgresql
                port: 5432
                protocol: TCP
                targetPort: 5432
      sizing:
        increment: 1
        initial: 3
        maximum: 10
        minimum: 1
        setup:
          additional:
            settings:
              - key: is_master
                value: false
              - key: disable_backup
                value: true
          initial:
            - settings:
                - key: is_master
                  value: true
                - key: disable_backup
                  value: true
            - settings:
                - key: is_master
                  value: false
                - key: disable_backup
                  value: false
      topologyqueries:
        - flags:
            - key: v1_is_master
              value: true
          format: array
          name: master
          scope: cluster
        - flags:
            - key: v1_is_master
              value: false
          format: array
          name: slaves
          scope: cluster
  dependencies:
    operator:
      name: psql-operator
      vendor: asag
      version: 0.2.1
  includes:
    - name: defaults-service
      vendor: asag
      version: 0.3.1
  name: psql
  settings:
    - name: environment
      schema:
        default: psql_prod
  version: 0.2.1
