kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: kube-ovn-cni
  namespace: {{ .Values.namespace }}
  annotations:
    kubernetes.io/description: |
      This daemon set launches the kube-ovn cni daemon.
spec:
  selector:
    matchLabels:
      app: kube-ovn-cni
  template:
    metadata:
      labels:
        app: kube-ovn-cni
        component: network
        type: infra
    spec:
      tolerations:
        - effect: NoSchedule
          operator: Exists
        - effect: NoExecute
          operator: Exists
        - key: CriticalAddonsOnly
          operator: Exists
      priorityClassName: system-node-critical
      serviceAccountName: kube-ovn-cni
      hostNetwork: true
      hostPID: true
      initContainers:
      - name: install-cni
        image: {{ .Values.global.registry.address }}/{{ .Values.global.images.kubeovn.repository }}:{{ .Values.global.images.kubeovn.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        command: ["/kube-ovn/install-cni.sh"]
        securityContext:
          runAsUser: 0
          privileged: true
        volumeMounts:
          - mountPath: /opt/cni/bin
            name: cni-bin
          {{- if .Values.cni_conf.MOUNT_LOCAL_BIN_DIR }}
          - mountPath: /usr/local/bin
            name: local-bin
          {{- end }}
      containers:
      - name: cni-server
        image: {{ .Values.global.registry.address }}/{{ .Values.global.images.kubeovn.repository }}:{{ .Values.global.images.kubeovn.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        command:
          - bash
          - /kube-ovn/start-cniserver.sh
        args:
          - --enable-mirror={{- .Values.debug.ENABLE_MIRROR }}
          - --mirror-iface={{- .Values.debug.MIRROR_IFACE }}
          - --node-switch={{ .Values.networking.NODE_SUBNET }}
          - --encap-checksum=true
          - --service-cluster-ip-range=
          {{- if eq .Values.networking.NET_STACK "dual_stack" -}}
          {{ .Values.dual_stack.SVC_CIDR }}
          {{- else if eq .Values.networking.NET_STACK "ipv4" -}}
          {{ .Values.ipv4.SVC_CIDR }}
          {{- else if eq .Values.networking.NET_STACK "ipv6" -}}
          {{ .Values.ipv6.SVC_CIDR }}
          {{- end }}
          {{- if eq .Values.networking.NETWORK_TYPE "vlan" }}
          - --iface=
          {{- else}}
          - --iface={{- .Values.networking.IFACE }}
          {{- end }}
          - --dpdk-tunnel-iface={{- .Values.networking.DPDK_TUNNEL_IFACE }}
          - --network-type={{- .Values.networking.TUNNEL_TYPE }}
          - --default-interface-name={{- .Values.networking.vlan.VLAN_INTERFACE_NAME }}
          - --cni-conf-dir={{ .Values.cni_conf.CNI_CONF_DIR }}
          - --cni-conf-file={{ .Values.cni_conf.CNI_CONF_FILE }}
          - --cni-conf-name={{- .Values.cni_conf.CNI_CONFIG_PRIORITY -}}-kube-ovn.conflist
          - --logtostderr=false
          - --alsologtostderr=true
          - --log_file=/var/log/kube-ovn/kube-ovn-cni.log
          - --log_file_max_size=0
          - --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
          - --kubelet-dir={{ .Values.kubelet_conf.KUBELET_DIR }}
          - --enable-tproxy={{ .Values.func.ENABLE_TPROXY }}
          - --ovs-vsctl-concurrency={{ .Values.performance.OVS_VSCTL_CONCURRENCY }}
        securityContext:
          runAsUser: 0
          privileged: true
        env:
          - name: ENABLE_SSL
            value: "{{ .Values.networking.ENABLE_SSL }}"
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          - name: KUBE_NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: POD_IPS
            valueFrom:
              fieldRef:
                fieldPath: status.podIPs
          - name: ENABLE_BIND_LOCAL_IP
            value: "{{- .Values.func.ENABLE_BIND_LOCAL_IP }}"
          - name: DBUS_SYSTEM_BUS_ADDRESS
            value: "unix:path=/host/var/run/dbus/system_bus_socket"
        volumeMounts:
          - name: host-modules
            mountPath: /lib/modules
            readOnly: true
          - name: shared-dir
            mountPath: {{ .Values.kubelet_conf.KUBELET_DIR }}/pods
          - mountPath: /etc/openvswitch
            name: systemid
            readOnly: true
          - mountPath: /etc/cni/net.d
            name: cni-conf
          - mountPath: /run/openvswitch
            name: host-run-ovs
            mountPropagation: Bidirectional
          - mountPath: /run/ovn
            name: host-run-ovn
          - mountPath: /host/var/run/dbus
            name: host-dbus
            mountPropagation: HostToContainer
          - mountPath: /var/run/netns
            name: host-ns
            mountPropagation: HostToContainer
          - mountPath: /var/log/kube-ovn
            name: kube-ovn-log
          - mountPath: /var/log/openvswitch
            name: host-log-ovs
          - mountPath: /var/log/ovn
            name: host-log-ovn
          - mountPath: /etc/localtime
            name: localtime
            readOnly: true
        readinessProbe:
          failureThreshold: 3
          periodSeconds: 7
          successThreshold: 1
          tcpSocket:
            port: 10665
          timeoutSeconds: 3
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 30
          periodSeconds: 7
          successThreshold: 1
          tcpSocket:
            port: 10665
          timeoutSeconds: 3
        resources:
          requests:
            cpu: {{ index .Values "kube-ovn-cni" "requests" "cpu" }}
            memory: {{ index .Values "kube-ovn-cni" "requests" "memory" }}
          limits:
            cpu: {{ index .Values "kube-ovn-cni" "limits" "cpu" }}
            memory: {{ index .Values "kube-ovn-cni" "limits" "memory" }}
      nodeSelector:
        kubernetes.io/os: "linux"
      volumes:
        - name: host-modules
          hostPath:
            path: /lib/modules
        - name: shared-dir
          hostPath:
            path: {{ .Values.kubelet_conf.KUBELET_DIR }}/pods
        - name: systemid
          hostPath:
            path: {{ .Values.OPENVSWITCH_DIR }}
        - name: host-run-ovs
          hostPath:
            path: /run/openvswitch
        - name: host-run-ovn
          hostPath:
            path: /run/ovn
        - name: cni-conf
          hostPath:
            path: {{ .Values.cni_conf.CNI_CONF_DIR }}
        - name: cni-bin
          hostPath:
            path: {{ .Values.cni_conf.CNI_BIN_DIR }}
        - name: host-ns
          hostPath:
            path: /var/run/netns
        - name: host-dbus
          hostPath:
            path: /var/run/dbus
        - name: kube-ovn-log
          hostPath:
            path: {{ .Values.log_conf.LOG_DIR }}/kube-ovn
        - name: localtime
          hostPath:
            path: /etc/localtime
        - name: host-log-ovs
          hostPath:
            path: {{ .Values.log_conf.LOG_DIR }}/openvswitch
        - name: host-log-ovn
          hostPath:
            path: {{ .Values.log_conf.LOG_DIR }}/ovn
        {{- if .Values.cni_conf.MOUNT_LOCAL_BIN_DIR }}
        - name: local-bin
          hostPath:
            path: {{ .Values.cni_conf.MOUNT_LOCAL_BIN_DIR }}
        {{- end }}
