kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: hostpath-csi-node
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: hostpath-csi-node
  template:
    metadata:
      labels:
        app: hostpath-csi-node
    spec:
      hostNetwork: true
      hostPID: true
      serviceAccount: hostpath-csi-service-account
      containers:
        - name: hostpath-csi-registrar
          image: skybig/csi-node-driver-registrar:v2.2.0
          imagePullPolicy: Always
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh", "-c", "rm -rf /registration/hostpath.csi.kubernetes.io /registration/hostpath.csi.kubernetes.io-reg.sock"]
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--kubelet-registration-path=/var/lib/kubelet/plugins/hostpath.csi.kubernetes.io/csi.sock"
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
          volumeMounts:
            - name: driver-dir
              mountPath: /csi
            - name: registration-dir
              mountPath: /registration

        - name: hostpath-csi-node
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          image: skybig/csi-hostpath:latest
          imagePullPolicy: Always
          args :
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--nodeid=$(KUBE_NODE_NAME)"
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
            - name: CSI_ENDPOINT
              value: unix://var/lib/kubelet/plugins/hostpath.csi.kubernetes.io/csi.sock
          volumeMounts:
            - name: endpoint-dir
              mountPath: /var/lib/kubelet

      volumes:
        - name: driver-dir
          hostPath:
            path: /var/lib/kubelet/plugins/hostpath.csi.kubernetes.io
            type: DirectoryOrCreate
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry
            type: DirectoryOrCreate
        - name: endpoint-dir
          hostPath:
            path: /var/lib/kubelet
            type: Directory
  updateStrategy:
    type: RollingUpdate