{%- set podTypeBootstrap = "yes" %}
{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: batch/v1
kind: Job
metadata:
  name: keystone-create-db
  namespace: {{ kolla_kubernetes_namespace }}
spec:
  template:
    spec:
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_controller %}
          {{ selector.key }}: {{ selector.value }}
      restartPolicy: OnFailure
      containers:
        - image: "{{ kolla_toolbox_image_full }}"
          name: main
          command: ["sh", "-c"]
          args:
            - ansible localhost -m mysql_db -a
              "login_host='{{ keystone_database_address }}'
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ keystone_database_name }}'"
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: database-password
                  key: password
        - image: "{{ kolla_toolbox_image_full }}"
          name: creating-keystone-user-and-permissions
          command: ["sh", "-c"]
          args:
            - ansible localhost -m mysql_user -a
              "login_host='{{ keystone_database_address }}'
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ keystone_database_name }}'
               password='$KEYSTONE_DATABASE_PASSWORD'
               host='%'
               priv='{{ keystone_database_name }}.*:ALL'
               append_privs='yes'"
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: database-password
                  key: password
            - name: KEYSTONE_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keystone-database-password
                  key: password
      volumes:
{{ lib.common_volumes(indent=8) }}
