---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ovirt-csi-driver-operator
  namespace: openshift-cluster-csi-drivers
spec:
  replicas: 1
  selector:
    matchLabels:
      name: ovirt-csi-driver-operator
  template:
    metadata:
      labels:
        name: ovirt-csi-driver-operator
    spec:
      serviceAccountName: ovirt-csi-driver-operator
      priorityClassName: system-cluster-critical
      nodeSelector:
        node-role.kubernetes.io/master: ""
      tolerations:
        - key: CriticalAddonsOnly
          operator: Exists
        - key: node-role.kubernetes.io/master
          operator: Exists
          effect: "NoSchedule"
      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
              value: /tmp/config/ovirt-engine-ca.pem
            - name: OVIRT_INSECURE
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_insecure
            - name: OVIRT_CA_BUNDLE
              valueFrom:
                secretKeyRef:
                  name: ovirt-credentials
                  key: ovirt_ca_bundle
          image: ${DRIVER_IMAGE}
          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
              # set a valid path only if ca bundle has content
              ovirt_cafile: ${OVIRT_CA_BUNDLE:+$OVIRT_CAFILE}
              ovirt_insecure: $OVIRT_INSECURE
              EOF
              if [[ -n "$OVIRT_CA_BUNDLE" ]]; then echo "$OVIRT_CA_BUNDLE" > $OVIRT_CAFILE ; fi
          volumeMounts:
            - name: config
              mountPath: /tmp/config

      containers:
        - name: ovirt-csi-driver-operator
          image: quay.io/openshift/origin-ovirt-csi-driver-operator:latest
          imagePullPolicy: IfNotPresent
          args:
            - start
            - "--node=$(KUBE_NODE_NAME)"
          env:
            - name: OPERATOR_NAME
              value: ovirt-csi-driver-operator
            - name: DRIVER_IMAGE
              value: quay.io/openshift/origin-ovirt-csi-driver:latest
            - name: PROVISIONER_IMAGE
              value: quay.io/openshift/origin-csi-external-provisioner:latest
            - name: ATTACHER_IMAGE
              value: quay.io/openshift/origin-csi-external-attacher:latest
            - name: RESIZER_IMAGE
              value: quay.io/openshift/origin-csi-external-resizer:latest
            - name: SNAPSHOTTER_IMAGE
              value: quay.io/openshift/origin-csi-external-snapshotter:latest
            - name: NODE_DRIVER_REGISTRAR_IMAGE
              value: quay.io/openshift/origin-csi-node-driver-registrar:latest
            - name: LIVENESS_PROBE_IMAGE
              value: quay.io/openshift/origin-csi-livenessprobe:latest
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName

            - name: OVIRT_CONFIG
              value: /tmp/config/ovirt-config.yaml
          volumeMounts:
            - name: config
              mountPath: /tmp/config
      volumes:
        - name: config
          emptyDir: {}
