apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: csi-gcs
spec:
  selector:
    matchLabels:
      app: csi-gcs
  template:
    metadata:
      labels:
        app: csi-gcs
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      priorityClassName: system-node-critical
      tolerations:
      - operator: "Exists"
      hostNetwork: true
      serviceAccount: csi-gcs
      containers:
      - name: csi-node-driver-registrar
        image: quay.io/k8scsi/csi-node-driver-registrar:v1.2.0
        imagePullPolicy: Always
        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/gcs.csi.ofek.dev/csi.sock
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        volumeMounts:
        - name: registration-dir
          mountPath: /registration
        - name: socket-dir
          mountPath: /csi
        resources:
          limits:
            cpu: 1
            memory: 1Gi
          requests:
            cpu: 10m
            memory: 20Mi
      - name: csi-provisioner
        image: quay.io/k8scsi/csi-provisioner:v1.6.0
        args:
          - "--csi-address=$(ADDRESS)"
          - "--extra-create-metadata"
          - "--enable-leader-election"
          - "--leader-election-namespace=$(NAMESPACE)"
        env:
          - name: ADDRESS
            value: /var/lib/csi/sockets/pluginproxy/csi.sock
          - name: NAMESPACE
            value: kube-system
        imagePullPolicy: "IfNotPresent"
        volumeMounts:
          - name: socket-dir
            mountPath: /var/lib/csi/sockets/pluginproxy/
      - name: csi-resizer
        image: quay.io/k8scsi/csi-resizer:v0.2.0
        args:
          - "--v=5"
          - "--csi-address=$(ADDRESS)"
          - "--leader-election"
          - "--leader-election-namespace=$(NAMESPACE)"
        env:
          - name: ADDRESS
            value: /var/lib/csi/sockets/pluginproxy/csi.sock
          - name: NAMESPACE
            value: kube-system
        imagePullPolicy: "IfNotPresent"
        volumeMounts:
          - name: socket-dir
            mountPath: /var/lib/csi/sockets/pluginproxy/
        resources:
          limits:
            cpu: 1
            memory: 1Gi
          requests:
            cpu: 10m
            memory: 20Mi
      - name: csi-gcs
        securityContext:
          privileged: true
          capabilities:
            add: ["SYS_ADMIN"]
          allowPrivilegeEscalation: true
        image: docker.io/ofekmeister/csi-gcs:latest
        imagePullPolicy: Always
        args:
        - "--node-name=$(KUBE_NODE_NAME)"
        # https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md
        - "--v=5"
        - "--delete-orphaned-pods=true"
        env:
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        volumeMounts:
        - name: fuse-device
          mountPath: /dev/fuse
        - name: mountpoint-dir
          mountPath: /var/lib/kubelet/pods
          mountPropagation: Bidirectional
        - name: socket-dir
          mountPath: /csi
        resources:
          limits:
            cpu: 1
            memory: 1Gi
          requests:
            cpu: 10m
            memory: 80Mi
      volumes:
      - name: fuse-device
        hostPath:
          path: /dev/fuse
      # https://kubernetes-csi.github.io/docs/deploying.html#driver-volume-mounts
      - name: socket-dir
        hostPath:
          path: /var/lib/kubelet/plugins/gcs.csi.ofek.dev
          type: DirectoryOrCreate
      - name: mountpoint-dir
        hostPath:
          path: /var/lib/kubelet/pods
          type: Directory
      - name: registration-dir
        hostPath:
          path: /var/lib/kubelet/plugins_registry
          type: Directory
