---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ovirt-csi-driver-operator
  namespace: openshift-cluster-csi-drivers
  annotations:
    config.openshift.io/inject-proxy: ovirt-csi-driver-operator
spec:
  replicas: 1
  selector:
    matchLabels:
      name: ovirt-csi-driver-operator
  template:
    metadata:
      annotations:
        target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
      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: ${OPERATOR_IMAGE}
          resources:
            requests:
              memory: 50Mi
              cpu: 10m
          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: ${OPERATOR_IMAGE}
          imagePullPolicy: IfNotPresent
          resources:
            requests:
              memory: 50Mi
              cpu: 10m
          args:
            - start
            - "--node=$(KUBE_NODE_NAME)"
            - -v=${LOG_LEVEL}
          env:
            - name: OPERATOR_NAME
              value: ovirt-csi-driver-operator
            - name: DRIVER_IMAGE
              value: ${DRIVER_IMAGE}
            - name: PROVISIONER_IMAGE
              value: ${PROVISIONER_IMAGE}
            - name: ATTACHER_IMAGE
              value: ${ATTACHER_IMAGE}
            - name: RESIZER_IMAGE
              value: ${RESIZER_IMAGE}
            - name: SNAPSHOTTER_IMAGE
              value: ${SNAPSHOTTER_IMAGE}
            - name: NODE_DRIVER_REGISTRAR_IMAGE
              value: ${NODE_DRIVER_REGISTRAR_IMAGE}
            - name: LIVENESS_PROBE_IMAGE
              value: ${LIVENESS_PROBE_IMAGE}
            - name: KUBE_RBAC_PROXY_IMAGE
              value: ${KUBE_RBAC_PROXY_IMAGE}
            - 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: {}
