# Copyright 2019 Nutanix Inc
#
# example usage: kubectl create -f <this_file>

---
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: csi-node-ntnx-plugin
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: csi-node-ntnx-plugin
  template:
    metadata:
      labels:
        app: csi-node-ntnx-plugin
    spec:
      serviceAccountName: csi-node-ntnx-plugin
      hostNetwork: true
      containers:
        - name: driver-registrar
          image: quay.io/k8scsi/csi-node-driver-registrar:v1.2.0
          args:
            - "--v=5"
            - "--csi-address=$(ADDRESS)"
            - "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
            - name: DRIVER_REG_SOCK_PATH
              value: /var/lib/kubelet/plugins/csi.nutanix.com/csi.sock
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
            - name: plugin-dir
              mountPath: /csi/
            - name: registration-dir
              mountPath: /registration
        - name: csi-node-ntnx-plugin
          securityContext:
            privileged: true
            allowPrivilegeEscalation: true
          image: ntnx/ntnx-csi:v2.2.0
          args:
            - "--drivername=csi.nutanix.com"
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--nodeid=$(NODE_ID)"
          env:
            - name: CSI_ENDPOINT
              value: unix:///csi/csi.sock
            - name: NODE_ID
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: LD_LIBRARY_PATH
              value: /iscsiadmroot/lib64:/iscsiadmroot/usr/lib64:$LD_LIBRARY_PATH
          volumeMounts:
            - name: plugin-dir
              mountPath: /csi
            - name: pods-mount-dir
              mountPath: /var/lib/kubelet
              # needed so that any mounts setup inside this container are
              # propagated back to the host machine.
              mountPropagation: "Bidirectional"
            - mountPath: /dev
              name: device-dir
            - mountPath: /lib/modules
              name: lib-dir
            - mountPath: /etc/iscsi
              name: iscsi-dir
            - mountPath: /sbin/iscsiadm
              name: iscsiadm
            - mountPath: /iscsiadmroot
              name: iscsiadmroot
            - mountPath: /lib64/ld-linux-x86-64.so.2
              name: ld-linux
          ports:
            - containerPort: 9808
              name: healthz
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: healthz
            initialDelaySeconds: 10
            timeoutSeconds: 3
            periodSeconds: 2
            failureThreshold: 3
        - name: liveness-probe
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /csi
              name: plugin-dir
          image: quay.io/k8scsi/livenessprobe:v1.1.0
          args:
            - --csi-address=/csi/csi.sock
      volumes:
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
            type: Directory
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/csi.nutanix.com/
            type: DirectoryOrCreate
        - name: pods-mount-dir
          hostPath:
            path: /var/lib/kubelet
            type: Directory
        - name: device-dir
          hostPath:
            path: /dev
        - name: iscsi-dir
          hostPath:
            path: /etc/iscsi
            type: Directory
        - name: iscsiadm
          hostPath:
            path: /sbin/iscsiadm
            type: File
        - name: lib-dir
          hostPath:
            path: /lib/modules
            type: Directory
        - name: iscsiadmroot
          hostPath:
            path: /
            type: Directory
        - name: ld-linux
          hostPath:
            path:  /lib64/ld-linux-x86-64.so.2
