{%- set podTypeBootstrap = "yes" %}
{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- set serviceName = kolla_kubernetes.template.vars.service_name %}
{%- set serviceType = kolla_kubernetes.template.vars.service_type %}
{%- set interface = kolla_kubernetes.template.vars.interface %}
{%- set serviceAuth = kolla_kubernetes.template.vars.service_auth %}
{%- set description = kolla_kubernetes.template.vars.description %}
{%- set endpoint = kolla_kubernetes.template.vars.endpoint %}
{%- set postfix = kolla_kubernetes.template.vars.postfix | default("") %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ serviceName }}-create-keystone-endpoint-{{ interface }}{{ postfix }}
  namespace: {{ kolla_kubernetes_namespace }}
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", "-xec"]
          args:
            - /usr/bin/ansible localhost -vvvv -m kolla_keystone_service
              -a "service_name={{ serviceName }}{{ postfix }}
                  service_type={{ serviceType }}{{ postfix }}
                  description='{{ description }}'
                  endpoint_region={{ openstack_region_name }}
                  url='{{ global[endpoint] }}'
                  interface='{{ interface }}'
                  region_name={{ openstack_region_name }}
                  auth={{ '{{ service_auth }}' }}"
              -e "{'service_auth':{{ global[serviceAuth] }}}"
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
          env:
            - name: ANSIBLE_NOCOLOR
              value: "1"
            - name: ANSIBLE_LIBRARY
              value: "/usr/share/ansible"
            - name: KEYSTONE_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: keystone-admin-password
                  key: password
      volumes:
{{ lib.common_volumes(indent=8) }}
      restartPolicy: OnFailure
