# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019-2020 Intel Corporation

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: "{{ .Release.Name }}"
  labels:
    app: "{{ .Release.Name }}"
spec:
  selector:
    matchLabels:
      app: "{{ .Release.Name }}"
  template:
    metadata:
      labels:
        app: "{{ .Release.Name }}"
      annotations:
        container.apparmor.security.beta.kubernetes.io/{{ .Release.Name }}: "{{ .Values.apparmor.profile }}"
    spec:
      tolerations:
      - key: cmk
        operator: Equal
        effect: NoSchedule
        value: "true"
      containers:
      - name:  "{{ .Release.Name }}"
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        securityContext:
          readOnlyRootFilesystem: true
        env:
        - name: DPDK_DRIVER
          valueFrom:
            configMapKeyRef:
              name: "{{ .Release.Name }}-config"
              key: DPDK_DRIVER
        - name: KERNEL_VF_DRIVERS
          valueFrom:
            configMapKeyRef:
              name: "{{ .Release.Name }}-config"
              key: KERNEL_VF_DRIVERS
        - name: MAX_NUM_DEVICES
          valueFrom:
            configMapKeyRef:
              name: "{{ .Release.Name }}-config"
              key: MAX_NUM_DEVICES
        - name: DEBUG
          valueFrom:
            configMapKeyRef:
              name: "{{ .Release.Name }}-config"
              key: DEBUG
        imagePullPolicy: "{{ .Values.pullPolicy }}"
        command:
        - "/usr/local/bin/intel_qat_device_plugin"
        - "-dpdk-driver"
        - "$(DPDK_DRIVER)"
        - "-kernel-vf-drivers"
        - "$(KERNEL_VF_DRIVERS)"
        - "-max-num-devices"
        - "$(MAX_NUM_DEVICES)"
        - "-debug"
        - "$(DEBUG)"
        volumeMounts:
        - name: devdir
          mountPath: /dev/vfio
          readOnly: true
        - name: pcidir
          mountPath: /sys/bus/pci
        - name: kubeletsockets
          mountPath: /var/lib/kubelet/device-plugins
      volumes:
      - name: devdir
        hostPath:
          path: /dev/vfio
      - name: pcidir
        hostPath:
          path: /sys/bus/pci
      - name: kubeletsockets
        hostPath:
          path: /var/lib/kubelet/device-plugins
