kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: csi-linode-node
  namespace: kube-system
  labels:
    app: csi-linode-node
spec:
  selector:
    matchLabels:
      app: csi-linode-node
  template:
    metadata:
      labels:
        app: csi-linode-node
        role: csi-linode
    spec:
      priorityClassName: system-node-critical
      serviceAccount: csi-node-sa
      initContainers:
        - name: init
          image: bitnami/kubectl:1.16.3-debian-10-r36
          command: 
            - /scripts/get-linode-id.sh
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
          - name: linode-info
            mountPath: /linode-info
          - name: get-linode-id
            mountPath: /scripts
      hostNetwork: true
      containers:
        - name: csi-node-driver-registrar
          image: k8s.gcr.io/sig-storage/csi-node-driver-registrar:v1.3.0
          args:
            - "--v=2"
            - "--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/linodebs.csi.linode.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-linode-plugin
          image: linode/linode-blockstorage-csi-driver:latest
          args :
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--token=$(LINODE_TOKEN)"
            - "--url=$(LINODE_API_URL)"
            - "--node=$(NODE_NAME)"
            - "--v=2"
          env:
            - name: CSI_ENDPOINT
              value: unix:///csi/csi.sock
            - name: LINODE_API_URL
              value: https://api.linode.com/v4
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: LINODE_TOKEN
              valueFrom:
                secretKeyRef:
                  name: linode
                  key: token
          imagePullPolicy: "Always"
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          volumeMounts:
            - name: linode-info
              mountPath: /linode-info
            - name: get-linode-id
              mountPath: /scripts
            - 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
      volumes:
        - name: linode-info
          emptyDir: {}
        - name: get-linode-id
          configMap:
            name: get-linode-id
            defaultMode: 493
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
            type: DirectoryOrCreate
        - name: kubelet-dir
          hostPath:
            path: /var/lib/kubelet
            type: Directory
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/linodebs.csi.linode.com
            type: DirectoryOrCreate
        - name: pods-mount-dir
          hostPath:
            path: /var/lib/kubelet
            type: Directory
        - name: device-dir
          hostPath:
            path: /dev
        # The following mounts are required to trigger host udevadm from container
        - name: udev-rules-etc
          hostPath:
            path: /etc/udev
            type: Directory
        - name: udev-rules-lib
          hostPath:
            path: /lib/udev
            type: Directory
        - name: udev-socket
          hostPath:
            path: /run/udev
            type: Directory
        - name: sys
          hostPath:
            path: /sys
            type: Directory
