#TODO: Force DaemonSet to not run on master.
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: ovirt-csi-node
  namespace: ovirt-csi-driver
spec:
  selector:
    matchLabels:
      app: ovirt-csi-driver
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: ovirt-csi-driver
    spec:
      serviceAccount: ovirt-csi-node-sa
      initContainers:
        - name: prepare-ovirt-config
          env:
            - name: OVIRT_URL
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_url
            - name: OVIRT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_username
            - name: OVIRT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_password
            - name: OVIRT_CAFILE
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_cafile
            - name: OVIRT_INSECURE
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_insecure
          image: busybox
          command:
            - /bin/sh
            - -c
            - |
              #!/bin/sh
              cat << EOF > /tmp/config/ovirt-config.yaml
              ovirt_url: $OVIRT_URL
              ovirt_username: $OVIRT_USERNAME
              ovirt_password: $OVIRT_PASSWORD
              ovirt_cafile: $OVIRT_CAFILE
              ovirt_insecure: $OVIRT_INSECURE
              EOF
          volumeMounts:
            - name: config
              mountPath: /tmp/config

      containers:
        - name: csi-driver-registrar
          imagePullPolicy: Always
          image: quay.io/k8scsi/csi-node-driver-registrar:v1.2.0
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--kubelet-registration-path=/var/lib/kubelet/plugins/ovirt.org/csi.sock"
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
            - name: registration-dir
              mountPath: /registration
        - name: ovirt-csi-driver
          securityContext:
            privileged: true
            allowPrivilegeEscalation: true
          imagePullPolicy: Always
          image: quay.io/rgolangh/ovirt-csi-driver:latest
          args:
            - "--endpoint=unix:/csi/csi.sock"
            - "--namespace=ovirt-csi-driver"
            - "--node-name=$(KUBE_NODE_NAME)"
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: OVIRT_CONFIG
              value: /tmp/config/ovirt-config.yaml
          volumeMounts:
#            - name: kubelet-dir
#              mountPath: /var/lib/kubelet
#              mountPropagation: "Bidirectional"
            - name: socket-dir
              mountPath: /csi
            - name: config
              mountPath: /tmp/config/
            - name: plugin-dir
              mountPath: /var/lib/kubelet/plugins
              mountPropagation: Bidirectional
            - name: host-dev
              mountPath: /dev
            - name: mountpoint-dir
              mountPath: /var/lib/kubelet/pods
              mountPropagation: Bidirectional
      volumes:
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry/
            type: Directory
        - name: kubelet-dir
          hostPath:
            path: /var/lib/kubelet
            type: Directory
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins
            type: Directory
        - name: socket-dir
          hostPath:
            path: /var/lib/kubelet/plugins/ovirt.org/
            type: DirectoryOrCreate
        - name: host-dev
          hostPath:
            path: /dev
        - name: config
          emptyDir: {}
        - name: mountpoint-dir
          hostPath:
            path: /var/lib/kubelet/pods
            type: DirectoryOrCreate
