{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}
{%- set loggerConfigmapName = "neutron-metadata-agent" %}
{%- set netHostTrue = "yes" %}
{%- import "services/common/common-lib.yml.j2" as lib with context %}
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: neutron-metadata-agent-{{ kolla_kubernetes.template.vars.type}}
  namespace: {{ kolla_kubernetes_namespace }}
  labels:
    component: neutron
    system: metadata-agent-{{ kolla_kubernetes.template.vars.type}}
spec:
  template:
    metadata:
      labels:
        component: neutron
        system: metadata-agent-{{ kolla_kubernetes.template.vars.type}}
    spec:
      hostNetwork: True
      nodeSelector:
{%- if kolla_kubernetes.template.vars.type == "compute" %}
{%- set selector = kolla_kubernetes_hostlabel_neutron_l3_agent_compute |
                   default(kolla_kubernetes_hostlabel_compute) %}
{%- else %}
{%- set selector = global['kolla_kubernetes_hostlabel_neutron_l3_agent_network_' ~ kolla_kubernetes.template.vars.type] |
                   default(kolla_kubernetes_hostlabel_network |
                     default(kolla_kubernetes_hostlabel_controller)
                   )
%}
{%- endif %}
          {{ selector.key }}: {{ selector.value }}
      containers:
        - image: "{{ neutron_metadata_agent_image_full }}"
          name: main
          securityContext:
            privileged: true
          volumeMounts:
{{ lib.common_volume_mounts(indent=12) }}
            - mountPath: {{ container_config_directory }}
              name: neutron-metadata-agent-config
              readOnly: true
            - mountPath: /var/lib/neutron/kolla/
              name: neutron-metadata-socket
            - mountPath: /run/netns/
              name: host-run-netns
              # shared: true # This seems not support in K8s yet :(
          env:
            - name: KOLLA_CONFIG_STRATEGY
              value: {{ config_strategy }}
{{ lib.common_containers(indent=8) }}
      volumes:
{{ lib.common_volumes(indent=8) }}
        - name: neutron-metadata-agent-config
          configMap:
            name: neutron-metadata-agent
            items:
            - key: neutron.conf
              path: neutron.conf
            - key: config.json
              path: config.json
            - key: ml2-conf.ini
              path: ml2_conf.ini
            - key: metadata-agent.ini
              path: metadata_agent.ini
        - name: host-run-netns
          hostPath:
            path: /run/netns
        - name: host-run
          hostPath:
            path: /run
        - name: neutron-metadata-socket
          hostPath:
            path: /var/lib/neutron/kolla/metadata_proxy
