kind: Deployment
apiVersion: apps/v1
metadata:
  name: {{ .Release.Name }}-kcsi-controller
  labels:
    app: {{ .Release.Name }}-kcsi-driver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Release.Name }}-kcsi-driver
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-kcsi-driver
        policy.cozystack.io/allow-to-apiserver: "true"
    spec:
      enableServiceLinks: false
      serviceAccountName: {{ .Release.Name }}-kcsi
      priorityClassName: system-cluster-critical
      tolerations:
        - key: CriticalAddonsOnly
          operator: Exists
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: "NoSchedule"
      containers:
        - name: csi-driver
          imagePullPolicy: Always
          image: "{{ $.Files.Get "images/kubevirt-csi-driver.tag" | trim }}"
          args:
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--infra-cluster-namespace=$(INFRACLUSTER_NAMESPACE)"
            - "--infra-cluster-labels=$(INFRACLUSTER_LABELS)"
            - "--v=5"
          ports:
            - name: healthz
              containerPort: 10301
              protocol: TCP
          env:
            - name: CSI_ENDPOINT
              value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: INFRACLUSTER_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: INFRACLUSTER_LABELS
              value: "cluster.x-k8s.io/cluster-name={{ .Release.Name }}"
            - name: INFRA_STORAGE_CLASS_ENFORCEMENT
              valueFrom:
                configMapKeyRef:
                  name: driver-config
                  key: infraStorageClassEnforcement
                  optional: true
          volumeMounts:
            - name: socket-dir
              mountPath: /var/lib/csi/sockets/pluginproxy/
            - name: kubeconfig
              mountPath: /etc/kubernetes/kubeconfig
              readOnly: true
          resources:
            limits:
              cpu: 512m
              memory: 512Mi
            requests:
              cpu: 125m
              memory: 128Mi
        - name: csi-provisioner
          image: quay.io/openshift/origin-csi-external-provisioner:latest
          resources:
            limits:
              cpu: 512m
              memory: 512Mi
            requests:
              cpu: 125m
              memory: 128Mi
          args:
            - "--csi-address=$(ADDRESS)"
            - "--default-fstype=ext4"
            - "--kubeconfig=/etc/kubernetes/kubeconfig/super-admin.svc"
            - "--v=5"
            - "--timeout=3m"
            - "--retry-interval-max=1m"
          env:
            - name: ADDRESS
              value: /var/lib/csi/sockets/pluginproxy/csi.sock
          volumeMounts:
            - name: socket-dir
              mountPath: /var/lib/csi/sockets/pluginproxy/
            - name: kubeconfig
              mountPath: /etc/kubernetes/kubeconfig
              readOnly: true
        - name: csi-attacher
          image: quay.io/openshift/origin-csi-external-attacher:latest
          args:
            - "--csi-address=$(ADDRESS)"
            - "--kubeconfig=/etc/kubernetes/kubeconfig/super-admin.svc"
            - "--v=5"
            - "--timeout=3m"
            - "--retry-interval-max=1m"
          env:
            - name: ADDRESS
              value: /var/lib/csi/sockets/pluginproxy/csi.sock
          volumeMounts:
            - name: socket-dir
              mountPath: /var/lib/csi/sockets/pluginproxy/
            - name: kubeconfig
              mountPath: /etc/kubernetes/kubeconfig
              readOnly: true
          resources:
            limits:
              cpu: 512m
              memory: 512Mi
            requests:
              cpu: 125m
              memory: 128Mi
        - name: csi-liveness-probe
          image: quay.io/openshift/origin-csi-livenessprobe:latest
          args:
            - "--csi-address=/csi/csi.sock"
            - "--probe-timeout=3s"
            - "--health-port=10301"
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
          resources:
            limits:
              cpu: 512m
              memory: 512Mi
            requests:
              cpu: 125m
              memory: 128Mi
      volumes:
        - name: socket-dir
          emptyDir: {}
        - secret:
            secretName: {{ .Release.Name }}-admin-kubeconfig
          name: kubeconfig
