kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: ovirt-csi-plugin
  namespace: ovirt-csi-driver
spec:
  serviceName: "ovirt-csi-driver"
  replicas: 1
  selector:
    matchLabels:
      app: ovirt-csi-driver
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: ovirt-csi-driver
    spec:
      serviceAccount: ovirt-csi-controller-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-external-attacher
          imagePullPolicy: Always
          image: quay.io/k8scsi/csi-attacher:v2.0.0
          args:
            - "--v=4"
            - "--csi-address=/csi/csi.sock"
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
        - name: csi-external-provisioner
          imagePullPolicy: Always
          image: quay.io/k8scsi/csi-provisioner:v1.5.0
          args:
            - "--v=9"
            - "--csi-address=/csi/csi.sock"
            - "--provisioner=csi.ovirt.org"
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
        - name: ovirt-csi-driver
          imagePullPolicy: Always
          image: quay.io/ovirt/csi-driver:latest
          args:
            - "--endpoint=unix:/csi/csi.sock"
            - "--namespace=ovirt-csi-driver"
            - "--ovirt-conf="
          ports:
          - containerPort: 9808
            name: healthz
            protocol: TCP
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: /healthz
              port: healthz
            initialDelaySeconds: 10
            timeoutSeconds: 3
            periodSeconds: 30
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: OVIRT_CONFIG
              value: /tmp/config/ovirt-config.yaml
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
            - name: config
              mountPath: /tmp/config/
        - name: liveness-probe
          imagePullPolicy: Always
          image: quay.io/k8scsi/livenessprobe:v2.0.0
          args:
           - "--v=5"
           - "--csi-address=/csi/csi.sock"
           - "--health-port=9808"
           - "--probe-timeout=3s"
          volumeMounts:
           - mountPath: /csi
             name: socket-dir
      volumes:
        - name: socket-dir
          emptyDir: {}
        - name: config
          emptyDir: {}
