# Source: pwnedworker/templates/deployment-postgres.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pwnedworker-postgres
  labels:
    app.kubernetes.io/name: pwnedworker
    app.kubernetes.io/instance: pwnedworker
    app.kubernetes.io/managed-by: Helm
    helm.sh/chart: pwnedworker-0.1.0
    app.kubernetes.io/component: postgres
spec:
  replicas: 1
  # "Recreate" (não "RollingUpdate"): só existe UM volume RWO — dois Pods do
  # Postgres tentando montá-lo ao mesmo tempo durante um rollout quebrariam.
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: pwnedworker
      app.kubernetes.io/instance: pwnedworker
      app.kubernetes.io/component: postgres
  template:
    metadata:
      labels:
        app.kubernetes.io/name: pwnedworker
        app.kubernetes.io/instance: pwnedworker
        app.kubernetes.io/component: postgres
    spec:
      serviceAccountName: pwnedworker
      nodeSelector:
        kubernetes.io/arch: amd64
      containers:
        - name: postgres
          image: registry.7dev.net.br/pwnedworker/postgres:16-alpine
          ports:
            - name: postgres
              containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: "pwnedworker"
            - name: POSTGRES_USER
              value: "pwnedworker"
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: pwnedworker
                  key: POSTGRES_PASSWORD
            - name: PGDATA
              value: /var/lib/postgresql/data/pgdata
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql/data
          readinessProbe:
            exec:
              command: ["pg_isready", "-U", "pwnedworker"]
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            exec:
              command: ["pg_isready", "-U", "pwnedworker"]
            initialDelaySeconds: 15
            periodSeconds: 20
          resources:
            limits:
              cpu: 500m
              memory: 1Gi
            requests:
              cpu: 250m
              memory: 512Mi
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: pwnedworker-postgres
