apiVersion: v1
kind: Pod
metadata:
  name: create-auth-tables
spec:
  tolerations:
   - key: preemptible
     value: "true"
  containers:
  - name: create-auth-tables
    image: "{{ create_auth_tables_image.image }}"
    command:
     - /bin/bash
     - -c
     - |
       set -ex
       # index creation isn't idempotent, don't create if a table exists
       USER_DATA=$(echo "SHOW TABLES LIKE 'users';" | mysql --defaults-extra-file=/auth-admin-secret/sql-config.cnf -s)
       if [ "$USER_DATA" != "users" ]; then
         mysql --defaults-extra-file=/auth-admin-secret/sql-config.cnf < ./create-auth-tables.sql
       fi
       echo 'show tables;' | mysql --defaults-extra-file=/auth-admin-secret/sql-config.cnf
       echo 'show grants;' | mysql --defaults-extra-file=/auth-admin-secret/sql-config.cnf
    volumeMounts:
      - mountPath: /auth-admin-secret
        readOnly: true
        name: auth-admin-secret
  volumes:
    - name: auth-admin-secret
      secret:
        secretName: "{{ auth_database.admin_secret_name }}"
  restartPolicy: Never
