#  Copyright (C) 2018 Yunify, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this work except in compliance with the License.
#  You may obtain a copy of the License in the LICENSE file, or 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.

kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: csi-qingcloud-node
  namespace: kube-system
  labels:
    role: "node"
spec:
  selector:
    matchLabels:
      role: "node"
  template:
    metadata:
      labels:
        role: "node"
    spec:
      serviceAccount: csi-qingcloud-node
      tolerations:
      - key: CriticalAddonsOnly
        operator: Exists
      - key: dedicated
        operator: Exists
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
      - effect: NoSchedule
        key: node.cloudprovider.kubernetes.io/uninitialized
        value: "true"
      hostNetwork: true
      containers:
        - name: node-registrar
          image: quay.io/k8scsi/csi-node-driver-registrar:v1.2.0
          resources:
            limits:
              memory: "20Mi"
              cpu: "10m"
            requests:
              memory: "20Mi"
              cpu: "10m"
          args:
            - "--csi-address=$(ADDRESS)"
            - "--kubelet-registration-path=/var/lib/kubelet/plugins/disk.csi.qingcloud.com/csi.sock"
            - "--v=5"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh", "-c", "rm -rf /registration/disk.csi.qingcloud.com /registration/disk.csi.qingcloud.com-reg.sock"]
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
            - name: registration-dir
              mountPath: /registration
        - name: csi-qingcloud
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          image: csiplugin/csi-qingcloud:canary
          resources:
            limits:
              memory: "50Mi"
              cpu: "50m"
            requests:
              memory: "50Mi"
              cpu: "50m"
          args :
            - "--config=/etc/config/config.yaml"
            - "--drivername=disk.csi.qingcloud.com"
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--maxvolume=10"
            - "--nodeid=$(NODE_ID)"
            - "--v=5"
          env:
            - name: NODE_ID
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: CSI_ENDPOINT
              value: unix://csi/csi.sock
          imagePullPolicy: "IfNotPresent"
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
            - name: dev-dir
              mountPath: /dev
              mountPropagation: "HostToContainer"
            - name: instance-id
              mountPath: /etc/qingcloud
              readOnly: true
            - name: server-config
              mountPath: /etc/config
      volumes:
        - name: socket-dir
          hostPath:
            path: /var/lib/kubelet/plugins/disk.csi.qingcloud.com/
            type: DirectoryOrCreate
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
        - name: dev-dir
          hostPath:
            path: /dev
            type: Directory
        - name: instance-id
          hostPath:
            path: /etc/qingcloud
        - name: server-config
          configMap:
            name: csi-qingcloud