apiVersion: v1
kind: Pod
metadata:
  name: pg-tester-app-{{ randAlphaNum 5 | lower }}
  annotations:
    "helm.sh/hook": test-success
  labels:
    app: postgres
    role: tester
spec:
  containers:
  - name: postgres-writer
    image: postgres:10.4
    command:
      - sh
      - -c
      - exec sh /app/write.sh
    env:
      - name: POSTGRES_PASSWORD_FILE
        value: /run/secrets/postgres/POSTGRES_PASSWORD
      - name: POSTGRES_USERNAME
        valueFrom:
          secretKeyRef:
            name: pg-generic-db-credentials
            key: POSTGRES_USER
      - name: POSTGRES_DB
        valueFrom:
          secretKeyRef:
            name: pg-generic-db-credentials
            key: POSTGRES_DB
      - name: POSTGRES_HOST
        valueFrom:
          configMapKeyRef:
            name: pg-generic-db-credentials
            key: DB_CONN
    volumeMounts:
      - name: db-secret
        mountPath: /run/secrets/postgres/
        readOnly: true
      - name: script
        mountPath: /app/
      - name: shared-data
        mountPath: /tmp
    imagePullPolicy: IfNotPresent
    resources:
      limits:
        cpu: 100m
        memory: 128Mi
  - name: postgres-reader
    image: postgres:10.4
    command:
      - sh
      - -c
      - exec sh /app/read.sh
    env:
      - name: POSTGRES_PASSWORD_FILE
        value: /run/secrets/postgres/POSTGRES_PASSWORD
      - name: POSTGRES_USERNAME
        valueFrom:
          secretKeyRef:
            name: pg-generic-db-credentials
            key: POSTGRES_USER
      - name: POSTGRES_DB
        valueFrom:
          secretKeyRef:
            name: pg-generic-db-credentials
            key: POSTGRES_DB
      - name: POSTGRES_HOST
        valueFrom:
          configMapKeyRef:
            name: pg-generic-db-credentials
            key: DB_CONN
    volumeMounts:
      - name: db-secret
        mountPath: /run/secrets/postgres/
        readOnly: true
      - name: script
        mountPath: /app/
      - name: shared-data
        mountPath: /tmp
    imagePullPolicy: IfNotPresent
    resources:
      limits:
        cpu: 100m
        memory: 128Mi
  restartPolicy: Never
  volumes:
    - name: db-secret
      secret:
        secretName: pg-generic-db-credentials
    - name: script
      configMap:
        name: postgres-test-script
    - name: shared-data
      emptyDir: {}
