{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- set netHostTrue = "yes" %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nova-libvirt
  labels:
    component: nova
    system: nova-libvirt
  namespace: {{ kolla_kubernetes_namespace }}
spec:
  template:
    metadata:
      labels:
        component: nova
        system: nova-libvirt
      annotations:
        pod.alpha.kubernetes.io/init-containers: '[
          {
             "name": "initialize-nova-libvirt",
             "image": "{{ nova_libvirt_image_full }}",
             "command": [
                 "sh",
                 "-xec",
                 "cp -a /config/..data/* /nova/;
{%- if enable_libvirt_tcp == "yes" %}
                  sed -i ''s|^listen_addr.*=.*|listen_addr=\"127.0.0.1\"|g'' /nova/libvirtd.conf;
{%- endif %}
{%- if enable_ceph == "yes" %}
                  mkdir -p /nova/secrets/;
                  cp -a /secret/a/..data/data /nova/secrets/{{ rbd_secret_uuid }}.xml;
                  cp -a /secret/b/..data/data /nova/secrets/{{ rbd_secret_uuid }}.base64;
                  cp -a /config2/..data/ceph.conf /nova;
{%- endif %}
             "],
             "volumeMounts": [
{%- if enable_ceph == "yes" %}
                {
                   "name": "ceph-conf",
                   "mountPath": "/config2"
                },
                {
                   "name": "nova-libvirt-secret",
                   "mountPath": "/secret/a/"
                },
                {
                   "name": "nova-libvirt-bin-secret",
                   "mountPath": "/secret/b/"
                },
{%- endif %}
                {
                   "name": "nova-libvirt-config",
                   "mountPath": "/config/"
                },
                {
                   "name": "nova-config",
                   "mountPath": "/nova/"
                }
             ]
          }
        ]'
    spec:
      hostNetwork: True
      hostPID: True
      nodeSelector:
{%- set selector = kolla_kubernetes_hostlabel_compute %}
          {{ selector.key }}: {{ selector.value }}
{%- if enable_libvirt_tcp != "yes" %}
      hostIPC: True
{%- endif %}
      containers:
        - name: main
          image: "{{ nova_libvirt_image_full }}"
          command:
            - /bin/bash
            - -c
            - |
              modprobe rbd;
              rpm -e qemu-system-x86;
              cp -a {{ container_config_directory }}/secrets /etc/libvirt;
              kolla_start
          securityContext:
            privileged: true
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
            - mountPath: {{ container_config_directory }}
              name: nova-config
            - mountPath: /var/lib/libvirt
              name: nova-libvirt-persistent-storage
            - mountPath: /var/lib/nova
              name: nova-compute-persistent-storage
            - mountPath: /lib/modules
              name: lib-modules
            - mountPath: /var/run
              name: run
            - mountPath: /dev
              name: dev
            - mountPath: /sys/fs/cgroup
              name: sys-fs-cgroup
            - mountPath: /nova
              name: nova-config
          env:
            - name: KOLLA_CONFIG_STRATEGY
              value: {{ config_strategy }}
{{ lib.common_containers(indent=8) }}
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: nova-compute-persistent-storage
          hostPath:
            path: /var/lib/nova
        - name: nova-libvirt-config
          configMap:
            name: nova-libvirt
        - name: nova-libvirt-persistent-storage
          hostPath:
            path: /var/lib/libvirt
        - name: lib-modules
          hostPath:
            path: /lib/modules
        - name: run
          hostPath:
            path: /var/run
        - name: dev
          hostPath:
            path: /dev
        - name: sys-fs-cgroup
          hostPath:
            path: /sys/fs/cgroup
        - name: nova-config
          emptyDir: {}
{%- if enable_ceph == "yes" %}
        - name: ceph-conf
          configMap:
            name: ceph-conf
        - name: nova-libvirt-secret
          secret:
            secretName: nova-libvirt
        - name: nova-libvirt-bin-secret
          secret:
            secretName: nova-libvirt-bin
{%- endif %}
