apiVersion: apps/v1
kind: DaemonSet
metadata:
  namespace: mayastor
  name: mayastor-csi
  labels:
    openebs/engine: mayastor
spec:
  selector:
    matchLabels:
      app: mayastor-csi
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  minReadySeconds: 10
  template:
    metadata:
      labels:
        app: mayastor-csi
    spec:
      hostNetwork: true
      nodeSelector:
        kubernetes.io/arch: amd64
      # NOTE: Each container must have mem/cpu limits defined in order to
      # belong to Guaranteed QoS class, hence can never get evicted in case of
      # pressure unless they exceed those limits. limits and requests must be
      # the same.
      containers:
      - name: mayastor-csi
        image: mayadata/mayastor-csi:v0.3.0
        imagePullPolicy: Always
        # we need privileged because we mount filesystems and use mknod
        securityContext:
          privileged: true
        env:
        - name: MY_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: RUST_BACKTRACE
          value: "1"
        args:
        - "--csi-socket=/csi/csi.sock"
        - "--node-name=$(MY_NODE_NAME)"
        - "-v"
        volumeMounts:
        - name: device
          mountPath: /dev
        - name: sys
          mountPath: /sys
        - name: run-udev
          mountPath: /run/udev
        - name: host-root
          mountPath: /host
        - name: plugin-dir
          mountPath: /csi
        - name: kubelet-dir
          mountPath: /var/lib/kubelet
          mountPropagation: "Bidirectional"
        resources:
          limits:
            cpu: "100m"
            memory: "50Mi"
          requests:
            cpu: "100m"
            memory: "50Mi"
      - name: csi-driver-registrar
        image: quay.io/k8scsi/csi-node-driver-registrar:v1.3.0
        args:
        - "--csi-address=/csi/csi.sock"
        - "--kubelet-registration-path=/var/lib/kubelet/plugins/mayastor.openebs.io/csi.sock"
        lifecycle:
          preStop:
            exec:
              # this is needed in order for CSI to detect that the plugin is gone
              command: ["/bin/sh", "-c", "rm -f /registration/io.openebs.csi-mayastor-reg.sock /csi/csi.sock"]
        volumeMounts:
        - name: plugin-dir
          mountPath: /csi
        - name: registration-dir
          mountPath: /registration
        resources:
          limits:
            cpu: "100m"
            memory: "50Mi"
          requests:
            cpu: "100m"
            memory: "50Mi"
      volumes:
      - name: device
        hostPath:
          path: /dev
          type: Directory
      - name: sys
        hostPath:
          path: /sys
          type: Directory
      - name: run-udev
        hostPath:
          path: /run/udev
          type: Directory
      - name: host-root
        hostPath:
          path: /
          type: Directory
      - name: registration-dir
        hostPath:
          path: /var/lib/kubelet/plugins_registry/
          type: Directory
      - name: plugin-dir
        hostPath:
          path: /var/lib/kubelet/plugins/mayastor.openebs.io/
          type: DirectoryOrCreate
      - name: kubelet-dir
        hostPath:
          path: /var/lib/kubelet
          type: Directory
