{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
   name: horizon
   namespace: {{ kolla_kubernetes_namespace }}
spec:
  replicas: {{ horizon_replicas }}
  strategy:
  template:
    metadata:
      labels:
        service: horizon
        type: api
      annotations:
        pod.beta.kubernetes.io/init-containers: '[
          {
              "name": "update-config",
              "image": "{{ kolla_toolbox_image_full }}",
              "imagePullPolicy": "IfNotPresent",
              "command": [
                  "/bin/sh",
                  "-c",
                  "cp -a /srv/configmap/..data/* /srv/pod-main-config/;
                   sed -i ''s|^OPENSTACK_HOST.*=.*|OPENSTACK_HOST=\"{{ kolla_kubernetes_external_vip }}\"|g'' /srv/pod-main-config/local_settings;
                   sed -i ''s|^OPENSTACK_KEYSTONE_URL.*=.*|OPENSTACK_KEYSTONE_URL=\"{{ keystone_admin_url }}\"|g'' /srv/pod-main-config/local_settings; "],
              "volumeMounts": [
                  {
                      "name": "horizon-configmap",
                      "mountPath": "/srv/configmap"
                  },
                  {
                      "name": "pod-main-config",
                      "mountPath": "/srv/pod-main-config"
                  }
              ]
          }
      ]'
    spec:
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_horizon |
                       default(kolla_kubernetes_hostlabel_controller)
%}
          {{ selector.key }}: {{ selector.value }}
      containers:
        - name: main
          image: "{{ horizon_image_full }}"
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
            - mountPath: {{ container_config_directory }}
              name: pod-main-config
          env:
            - name: KOLLA_CONFIG_STRATEGY
              value: {{ config_strategy }}
{{ lib.common_containers(indent=8) }}
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: pod-main-config
          emptyDir: {}
        - name: horizon-configmap
          configMap:
            name: horizon
            items:
            - key: horizon.conf
              path: horizon.conf
            - key: config.json
              path: config.json
            - key: local-settings
              path: local_settings
