{%- 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
spec:
  parallelism: 1
  completions: 1
  template:
    spec:
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_controller %}
          {{ selector.key }}: {{ selector.value }}
      containers:
        - image: "{{ kolla_toolbox_image_full }}"
          name: main
          command: ["sh", "-c"]
          args:
            - ansible localhost  -m mysql_db -a
              "login_host=mariadb
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ nova_database_name }}'" &&
              ansible localhost  -m mysql_db -a
              "login_host=mariadb
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ nova_api_database_name }}'" &&
              ansible localhost -m mysql_user -a
              "login_host=mariadb
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ nova_database_name }}'
               password='$NOVA_DATABASE_PASSWORD'
               host='%'
               priv='{{ nova_database_name }}.*:ALL'
               append_privs='yes'" &&
              ansible localhost -m mysql_user -a
              "login_host=mariadb
               login_port='{{ mariadb_port }}'
               login_user='{{ database_user }}'
               login_password='$DATABASE_PASSWORD'
               name='{{ nova_api_database_name }}'
               password='$NOVA_API_DATABASE_PASSWORD'
               host='%'
               priv='{{ nova_api_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: NOVA_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: nova-database-password
                  key: password
            - name: NOVA_API_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: nova-api-database-password
                  key: password
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: nova-api-config
          configMap:
            name: nova-api
        - name: lib-modules
          hostPath:
            path: /lib/modules
      restartPolicy: OnFailure
metadata:
  name: nova-create-db
  namespace: {{ kolla_kubernetes_namespace }}
