---
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: csi-cbs-node
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: cbs-csi-node
  template:
    metadata:
      labels:
        app: cbs-csi-node
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: beta.kubernetes.io/instance-type
                    operator: NotIn
                    values:
                      - CHC
      serviceAccount: cbs-csi-node-sa
      hostNetwork: true
      hostPID: true
      dnsPolicy: ClusterFirstWithHostNet
      priorityClassName: system-node-critical
      hostAliases:
        - ip: "169.254.0.23"
          hostnames:
            - "metadata.tencentyun.com"
      containers:
        - name: driver-registrar
          image: ccr.ccs.tencentyun.com/tkeimages/csi-node-driver-registrar:v2.0.1
          imagePullPolicy: "Always"
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--kubelet-registration-path=/var/lib/kubelet/plugins/com.tencent.cloud.csi.cbs/csi.sock"
          lifecycle:
            preStop:
              exec:
                command: [
                  "/bin/sh", "-c",
                  "rm -rf /registration/com.tencent.cloud.csi.cbs \
                  /registration/com.tencent.cloud.csi.cbs-reg.sock"
                ]
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
            - name: plugin-dir
              mountPath: /csi
            - name: registration-dir
              mountPath: /registration
        - name: cbs-csi
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          image: ccr.ccs.tencentyun.com/tkeimages/csi-tencentcloud-cbs:v2.2.3
          command:
            - "/csi-tencentcloud-cbs"
          args:
            - "--v=5"
            - "--logtostderr=true"
            - "--endpoint=unix:///csi/csi.sock"
          env:
            - name: TENCENTCLOUD_API_SECRET_ID
              valueFrom:
                secretKeyRef:
                  name: cbs-csi-api-key
                  key: TENCENTCLOUD_CBS_API_SECRET_ID
                  optional: true
            - name: TENCENTCLOUD_API_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: cbs-csi-api-key
                  key: TENCENTCLOUD_CBS_API_SECRET_KEY
                  optional: true
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          imagePullPolicy: "Always"
          volumeMounts:
            - name: plugin-dir
              mountPath: /csi
            - name: plugins-mount-dir
              mountPath: /var/lib/kubelet/plugins
              mountPropagation: "Bidirectional"
            - name: pods-mount-dir
              mountPath: /var/lib/kubelet/pods
              mountPropagation: "Bidirectional"
            - name: host-dev
              mountPath: /dev
            - name: host-sys
              mountPath: /sys
            - name: lib-modules
              mountPath: /lib/modules
              readOnly: true
      volumes:
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/com.tencent.cloud.csi.cbs
            type: DirectoryOrCreate
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
            type: Directory
        - name: plugins-mount-dir
          hostPath:
            path: /var/lib/kubelet/plugins
            type: Directory
        - name: pods-mount-dir
          hostPath:
            path: /var/lib/kubelet/pods
            type: Directory
        - name: host-dev
          hostPath:
            path: /dev
        - name: host-sys
          hostPath:
            path: /sys
        - name: lib-modules
          hostPath:
            path: /lib/modules
