kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: csi-ecfsplugin
spec:
  selector:
    matchLabels:
      app: csi-ecfsplugin
  template:
    metadata:
      labels:
        app: csi-ecfsplugin
    spec:
      serviceAccount: csi-driver-registrar
      hostNetwork: true
      # to use e.g. Rook orchestrated cluster, and mons' FQDN is
      # resolved through k8s service, set dns policy to cluster first
      dnsPolicy: ClusterFirstWithHostNet      
      containers:
        - name: driver-registrar
          image: gcr.io/gke-release/csi-driver-registrar:v1.0.1-gke.0
          args:
#            - "--v=5"
            - "--v=10"
            - "--csi-address=$(ADDRESS)"
            - "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)"
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh", "-c", "rm -rf /registration/csi-ecfsplugin /var/lib/kubelet/plugins_registry/csi-ecfsplugin/csi.sock"]
          env:
            - name: ADDRESS
              value: /var/lib/kubelet/plugins_registry/csi-ecfsplugin/csi.sock
            - name: DRIVER_REG_SOCK_PATH
              value: /var/lib/kubelet/plugins_registry/csi-ecfsplugin/csi.sock
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
            - name: socket-dir
              mountPath: /var/lib/kubelet/plugins_registry/csi-ecfsplugin
            - name: registration-dir
              mountPath: /registration
        - name: csi-ecfsplugin
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          image: docker.io/elastifileio/ecfs-provisioner-csi:${PLUGIN_TAG}
          imagePullPolicy: "Always"
          args:
            - "--nodeid=$(NODE_ID)"
            - "--endpoint=$(CSI_ENDPOINT)"
#            - "--v=5"
            - "--v=10"
            - "--drivername=csi-ecfsplugin"
          env:
            - name: NODE_ID
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: CSI_ENDPOINT
              value: unix:///var/lib/kubelet/plugins_registry/csi-ecfsplugin/csi.sock
            - name: CSI_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: EKFS
              value: "${EKFS}"
            - name: CSI_EFAAS_INSTANCE
              value: "${CSI_EFAAS_INSTANCE}"
            - name: EFAAS_URL
              value: "${EFAAS_URL}"
            - name: CSI_GCP_PROJECT_NUMBER
              value: "${CSI_GCP_PROJECT_NUMBER}"
          volumeMounts:
            - name: plugin-dir
              mountPath: /var/lib/kubelet/plugins_registry/csi-ecfsplugin
            - name: pods-mount-dir
              mountPath: /var/lib/kubelet/pods
              mountPropagation: "Bidirectional"
            - mountPath: /sys
              name: host-sys
            - name: lib-modules
              mountPath: /lib/modules
              readOnly: true
            - name: host-dev
              mountPath: /dev
      volumes:
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/csi-ecfsplugin
            type: DirectoryOrCreate
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
            type: Directory
        - name: pods-mount-dir
          hostPath:
            path: /var/lib/kubelet/pods
            type: Directory
        - name: socket-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/csi-ecfsplugin
            type: DirectoryOrCreate
        - name: host-sys
          hostPath:
            path: /sys
        - name: lib-modules
          hostPath:
            path: /lib/modules
        - name: host-dev
          hostPath:
            path: /dev
