{{- if .Values.postgresql.enabled }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "ovirt-api-simulator.fullname" . }}-postgresql
spec:
  serviceName: {{ include "ovirt-api-simulator.fullname" . }}-postgresql
  replicas: 1
  selector:
    matchLabels:
      app: {{ include "ovirt-api-simulator.name" . }}-postgresql
  template:
    metadata:
      labels:
        app: {{ include "ovirt-api-simulator.name" . }}-postgresql
    spec:
      containers:
        - name: postgres
          image: postgres:17.5-bookworm
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: {{ .Values.postgresql.auth.database | quote }}
            - name: POSTGRES_USER
              value: {{ .Values.postgresql.auth.username | quote }}
            - name: POSTGRES_PASSWORD
              value: {{ .Values.postgresql.auth.password | quote }}
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: {{ .Values.postgresql.persistence.size }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "ovirt-api-simulator.fullname" . }}-postgresql
spec:
  selector:
    app: {{ include "ovirt-api-simulator.name" . }}-postgresql
  ports:
    - port: 5432
{{- end }}
