# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: driver
spec:
  selector:
    matchLabels:
      app: driver
  template:
    metadata:
      labels:
        app: driver
    spec:
      serviceAccountName: node-cache-driver
      nodeSelector:
        kubernetes.io/os: linux
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-cache.gke.io
                operator: Exists
      containers:
        - name: registrar
          image: gke.gcr.io/csi-node-driver-registrar:v2.9.4-gke.3@sha256:e9ff64a44314d49168ec5fae8ab98d75b4bd5aae00e03faf5b0d5ef94cb72a83
          args:
            - --v=5
            - --csi-address=/csi/csi.sock
            - --kubelet-registration-path=/var/lib/kubelet/plugins/phase1-checkpoint.csi.storage.gke.io/csi.sock
          volumeMounts:
            - name: plugin-dir
              mountPath: /csi
            - name: registration-dir
              mountPath: /registration
        - name: csi
          image: imagetag/driver
          args:
            - --v=5
            - --endpoint=unix:/csi/csi.sock
            - --driver-name=node-cache.csi.storage.gke.io
            - --namespace=$(NAMESPACE)
            - --node-name=$(NODE_NAME)
            - --volume-type-map=volume-type-map
          env:
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          securityContext:
            privileged: true
          volumeMounts:
            - name: kubelet-pods-dir
              mountPath: /var/lib/kubelet/pods
              mountPropagation: "Bidirectional"
            - name: plugin-dir
              mountPath: /csi
            - name: dev
              mountPath: /dev
      volumes:
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
            type: Directory
        - name: kubelet-pods-dir
          hostPath:
            path: /var/lib/kubelet/pods
            type: Directory
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/phase1-checkpoint.csi.storage.gke.io
            type: DirectoryOrCreate
        - name: dev
          hostPath:
            path: /dev
            type: DirectoryOrCreate
