# Copyright 2021 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:
      serviceAccount: csi-node-ntnx-plugin
      hostNetwork: true
      containers:
        - name: driver-registrar
          image: k8s.gcr.io/sig-storage/csi-node-driver-registrar:v2.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: quay.io/karbon/ntnx-csi:v2.4.1
          args :
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--nodeid=$(NODE_ID)"
          env:
            - name: CSI_ENDPOINT
              value: unix:///csi/csi.sock
            - name: NODE_ID
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
          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: /etc/iscsi
              name: iscsi-dir
            - mountPath: /host
              name: root-dir
              # This is needed because mount is run from host using chroot.
              mountPropagation: "Bidirectional"
          ports:
            - containerPort: 9808
              name: http-endpoint
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: http-endpoint
            initialDelaySeconds: 10
            timeoutSeconds: 3
            periodSeconds: 2
            failureThreshold: 3
        - name: liveness-probe
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /csi
              name: plugin-dir
          image: k8s.gcr.io/sig-storage/livenessprobe:v2.3.0
          args:
            - --csi-address=/csi/csi.sock
            - --http-endpoint=:9808
      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: root-dir
          hostPath:
            path: /
            type: Directory
