# This file contains the contrail controller component.
# It will be installed as DaemonSets on the infra node
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: contrail-controller-control
  namespace: contrail-system
  labels:
    app: contrail-controller-control
spec:
  template:
    metadata:
      labels:
        app: contrail-controller-control
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: "node-role.kubernetes.io/infra"
                operator: Exists
      hostNetwork: true
      initContainers:
      - name: contrail-node-init
        image: "{{ contrail_registry }}/contrail-node-init:{{ contrail_container_tag }}"
        imagePullPolicy: "IfNotPresent"
        securityContext:
          privileged: true
        env:
{% if os_firewall_use_firewalld is defined and os_firewall_use_firewalld.lower() == 'true' %}
        - name: CONFIGURE_FIREWALLD
          value: "true"
        - name: FIREWALL_ZONE
          value: "{{firewall_zone}}"
{% else %}
        - name: CONFIGURE_IPTABLES
          value: "true"
        - name: IPTABLES_CHAIN
          value: "OS_FIREWALL_ALLOW"
{% endif %}
        - name: NODE_TYPE
          value: "control"
        - name: CONTRAIL_STATUS_IMAGE
          value: "{{ contrail_registry }}/contrail-status:{{ contrail_container_tag }}"
        envFrom:
        - configMapRef:
            name: env
        volumeMounts:
        - mountPath: /host/usr/bin
          name: host-usr-bin
      containers:
      - name: contrail-controller-control
        image: "{{ contrail_registry }}/contrail-controller-control-control:{{ contrail_container_tag }}"
        imagePullPolicy: "IfNotPresent"
        securityContext:
          privileged: true
        envFrom:
        - configMapRef:
            name: env
        - configMapRef:
            name: configzookeeperenv
        volumeMounts:
        - mountPath: /var/log/contrail
          name: control-logs
        - mountPath: /etc/localtime
          name: localtime
      - name: contrail-controller-control-dns
        image: "{{ contrail_registry }}/contrail-controller-control-dns:{{ contrail_container_tag }}"
        imagePullPolicy: "IfNotPresent"
        securityContext:
          privileged: true
        envFrom:
        - configMapRef:
            name: env
        volumeMounts:
        - mountPath: /etc/contrail
          name: dns-config
        - mountPath: /var/log/contrail
          name: control-logs
        - mountPath: /etc/localtime
          name: localtime
      - name: contrail-controller-control-named
        image: "{{ contrail_registry }}/contrail-controller-control-named:{{ contrail_container_tag }}"
        imagePullPolicy: "IfNotPresent"
        securityContext:
          privileged: true
        envFrom:
        - configMapRef:
            name: env
        - configMapRef:
            name: configzookeeperenv
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /etc/contrail
          name: dns-config
        - mountPath: /var/log/contrail
          name: control-logs
        - mountPath: /etc/localtime
          name: localtime
      - name: contrail-controller-control-nodemgr
        image: "{{ contrail_registry }}/contrail-nodemgr:{{ contrail_container_tag }}"
        imagePullPolicy: "IfNotPresent"
        securityContext:
          privileged: true
        envFrom:
        - configMapRef:
            name: env
        - configMapRef:
            name: configzookeeperenv
        - configMapRef:
            name: nodemgr-config
        env:
        - name: NODE_TYPE
          value: control
# todo: there is type Socket in new kubernetes, it is possible to use full
# path:
# hostPath:
#   path: /var/run/docker.sock and
#   type: Socket
        volumeMounts:
        - mountPath: /var/log/contrail
          name: control-logs
        - mountPath: /mnt
          name: docker-unix-socket
        - mountPath: /etc/localtime
          name: localtime
      volumes:
      - name: control-logs
        hostPath:
          path: /var/log/contrail/control
      - name: docker-unix-socket
        hostPath:
          path: /var/run
      - name: dns-config
        emptyDir: {}
      - name: host-usr-bin
        hostPath:
          path: /usr/bin
      - name: pod-secret
        secret:
          secretName: contrail-kubernetes-token
      - name: localtime
        hostPath:
          path: /etc/localtime
{% if contrail_registry_username is defined and contrail_registry_password %}
      imagePullSecrets:
      - name: contrail-registry-secret
{% endif %}
---
