---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: csi-blob-controller
  namespace: kube-system
spec:
  replicas: 2
  selector:
    matchLabels:
      app: csi-blob-controller
  template:
    metadata:
      labels:
        app: csi-blob-controller
    spec:
      hostNetwork: true
      serviceAccountName: csi-blob-controller-sa
      nodeSelector:
        kubernetes.io/os: linux  # add "kubernetes.io/role: master" to run controller on master node
      priorityClassName: system-cluster-critical
      tolerations:
        - key: "node-role.kubernetes.io/master"
          operator: "Equal"
          value: "true"
          effect: "NoSchedule"
      containers:
        - name: csi-provisioner
          image: mcr.microsoft.com/oss/kubernetes-csi/csi-provisioner:v1.4.0
          args:
            - "-v=5"
            - "--csi-address=$(ADDRESS)"
            - "--enable-leader-election"
            - "--leader-election-type=leases"
            - "--timeout=60s"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          volumeMounts:
            - mountPath: /csi
              name: socket-dir
          resources:
            limits:
              cpu: 100m
              memory: 100Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: liveness-probe
          image: mcr.microsoft.com/oss/kubernetes-csi/livenessprobe:v2.0.0
          args:
            - --csi-address=/csi/csi.sock
            - --probe-timeout=3s
            - --health-port=29632
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
          resources:
            limits:
              cpu: 100m
              memory: 100Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: blob
          image: mcr.microsoft.com/k8s/csi/blob-csi:latest
          imagePullPolicy: IfNotPresent
          args:
            - "--v=5"
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--metrics-address=0.0.0.0:29634"
          ports:
            - containerPort: 29632
              name: healthz
              protocol: TCP
            - containerPort: 29634
              name: metrics
              protocol: TCP
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: /healthz
              port: healthz
            initialDelaySeconds: 30
            timeoutSeconds: 10
            periodSeconds: 30
          env:
            - name: AZURE_CREDENTIAL_FILE
              valueFrom:
                configMapKeyRef:
                  name: azure-cred-file
                  key: path
                  optional: true
            - name: CSI_ENDPOINT
              value: unix:///csi/csi.sock
            - name: AZURE_ENVIRONMENT_FILEPATH  # For Azure Stack Cloud
              value: /etc/kubernetes/azurestackcloud.json
          volumeMounts:
            - mountPath: /csi
              name: socket-dir
            - mountPath: /etc/kubernetes/
              name: azure-cred
            - mountPath: /var/lib/waagent/ManagedIdentity-Settings
              readOnly: true
              name: msi
            - name: ssl
              mountPath: /etc/ssl/certs
              readOnly: true
          resources:
            limits:
              cpu: 200m
              memory: 200Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: csi-resizer
          image: mcr.microsoft.com/oss/kubernetes-csi/csi-resizer:v0.5.0
          args:
            - "-csi-address=$(ADDRESS)"
            - "-v=5"
            - "-leader-election"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
          resources:
            limits:
              cpu: 100m
              memory: 100Mi
            requests:
              cpu: 10m
              memory: 20Mi
      volumes:
        - name: socket-dir
          emptyDir: {}
        - name: azure-cred
          hostPath:
            path: /etc/kubernetes/
            type: Directory
        - name: msi
          hostPath:
            path: /var/lib/waagent/ManagedIdentity-Settings
        - name: ssl
          hostPath:
            path: /etc/ssl/certs
