apiVersion: v1
kind: ConfigMap
metadata:
  name: db-init-ironic
  labels:
    system: openstack
    type: configuration
    component: database

data:
  db-init.sh: |
    #!/usr/bin/env bash

    data_dir=/postgresql-data/data

    if [[ ! -e $data_dir ]]
    then
      mkdir $data_dir
    fi

    cp /postgresql-conf/postgresql.conf  $data_dir/postgresql.conf
    cp /postgresql-conf/pg-hba.conf  $data_dir/pg_hba.conf


    export PGUSER=postgres
    psql <<- EOSQL
        CREATE DATABASE {{.Values.db_name}};
        CREATE ROLE {{.Values.db_user}} WITH ENCRYPTED PASSWORD '{{.Values.db_password}}' LOGIN;
        GRANT ALL PRIVILEGES ON DATABASE {{.Values.db_name}} TO {{.Values.db_user}};

        CREATE DATABASE {{.Values.inspector_db_name}};
        CREATE ROLE {{.Values.inspector_db_user}} WITH ENCRYPTED PASSWORD '{{.Values.inspector_db_password}}' LOGIN;
        GRANT ALL PRIVILEGES ON DATABASE {{.Values.inspector_db_name}} TO {{.Values.inspector_db_user}};


    EOSQL



