apiVersion: v1
kind: Pod
metadata:
  name: vault-server-test
  namespace: vault
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: vault-server-test
      image: hashicorp/vault:1.21.2
      imagePullPolicy: IfNotPresent
      env:
        - name: VAULT_ADDR
          value: http://vault.vault.svc:8200
      command:
        - /bin/sh
        - -c
        - |
          echo "Checking for sealed info in 'vault status' output"
          ATTEMPTS=10
          n=0
          until [ "$n" -ge $ATTEMPTS ]
          do
            echo "Attempt" $n...
            vault status -format yaml | grep -E '^sealed: (true|false)' && break
            n=$((n+1))
            sleep 5
          done
          if [ $n -ge $ATTEMPTS ]; then
            echo "timed out looking for sealed info in 'vault status' output"
            exit 1
          fi

          exit 0
      volumeMounts:
        - mountPath: /opt/backups/
          name: vault-storage-backup
          readOnly: false
  volumes:
    - name: vault-storage-backup
      persistentVolumeClaim:
        claimName: vault-storage-backup
  restartPolicy: Never
