apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: openvswitch-db
  labels:
    component: openvswitch
    system: openvswitch-db
  namespace: default
spec:
  template:
    metadata:
      name: openvswitch-db
      labels:
        component: openvswitch
        system: openvswitch-db
      namespace: default
      annotations:
        pod.alpha.kubernetes.io/init-containers: '[
          {
             "name": "initialize-ovs-db",
             "image": "{{ openvswitch_db_image_full }}",
             "command": [
                 "sh",
                 "-c",
                 "mkdir -p /var/log/kolla/openvswitch;
                  DB=/etc/openvswitch/conf.db;
                  /usr/bin/ovsdb-tool create $DB;
                  echo $(date) >> /var/log/kolla/db-create.log;" ],
             "volumeMounts": [
                {
                   "name": "openvswitch-db",
                   "mountPath": "/etc/openvswitch/"
                },
                {
                   "name": "kolla-logs",
                   "mountPath": "/var/log/kolla/"
                }
             ]
          }
        ]'
    spec:
      hostNetwork: True
      hostIPC: True
      containers:
        - image: "{{ openvswitch_db_image_full }}"
          name: openvswitch-db
          securityContext:
            privileged: true
          env:
            - name: KOLLA_CONFIG_STRATEGY
              value: {{ config_strategy }}
          volumeMounts:
            - mountPath: {{ container_config_directory }}
              name: openvswitch-db-config
              readOnly: true
            - mountPath: /etc/openvswitch
              name: openvswitch-db
            - mountPath: /var/run/openvswitch
              name: openvswitch-run
            - mountPath: /dev
              name: host-dev
            - mountPath: /etc/localtime
              name: host-etc-localtime
              readOnly: true
            - mountPath: /var/log/kolla
              name: kolla-logs
          command: ["sh", "-c"]
          args:
            - /usr/sbin/ovsdb-server
              /etc/openvswitch/conf.db
              -vconsole:emer
              -vsyslog:err
              -vfile:info
              --remote=punix:/var/run/openvswitch/db.sock
              --remote=ptcp:6640:0.0.0.0
              --log-file=/var/log/kolla/openvswitch/ovsdb-server.log
      volumes:
        - name: openvswitch-db-config
          configMap:
            name: openvswitch-db-server-configmap
        - name: openvswitch-db
          emptyDir: {}
        - name: openvswitch-run
          hostPath:
            path: /var/run/openvswitch
        - name: host-dev
          hostPath:
            path: /dev
        - name: host-etc-localtime
          hostPath:
            path: /etc/localtime
        - name: kolla-logs
          emptyDir: {}
