# Copyright 2020 Cambricon, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: cambricon-device-plugin-daemonset
  namespace: kube-system
spec:
  selector:
    matchLabels:
      name: cambricon-device-plugin-ds
  template:
    metadata:
      # Mark this pod as a critical add-on; when enabled, the critical add-on scheduler
      # reserves resources for critical add-on pods so that they can be rescheduled after
      # a failure.  This annotation works in tandem with the toleration below.
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ""
      labels:
        name: cambricon-device-plugin-ds
    spec:
      tolerations:
        # Allow this pod to be rescheduled while the node is in "critical add-ons only" mode.
        # This, along with the annotation above marks this pod as a critical add-on.
        - key: CriticalAddonsOnly
          operator: Exists
        - key: cambricon.com/mlu
          operator: Exists
          effect: NoSchedule
      containers:
        - image: cambricon-k8s-device-plugin:v1.1.1
          name: cambricon-device-plugin-ctr
          command:
            - /usr/bin/k8s-device-plugin
          args:
            - -mode
            - default # switch mode here
          env:
            # change this if env-share mode or sriov mode is enabled.
            - name: VIRTUALIZATION_NUM
              value: "0"
          securityContext:
            privileged: true
          volumeMounts:
            - name: device-plugin
              mountPath: /var/lib/kubelet/device-plugins
            # mount sys if sriov mode is enabled
            - name: sys
              mountPath: /sys
      volumes:
        - name: device-plugin
          hostPath:
            path: /var/lib/kubelet/device-plugins
        # mount sys if sriov mode is enabled
        - name: sys
          hostPath:
            path: /sys
