---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: csi-azurefile-controller
  namespace: kube-system
spec:
  replicas: 2
  selector:
    matchLabels:
      app: csi-azurefile-controller
  template:
    metadata:
      labels:
        app: csi-azurefile-controller
    spec:
      hostNetwork: true  # only required for MSI enabled cluster
      serviceAccountName: csi-azurefile-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: "Exists"
          effect: "NoSchedule"
        - key: "node-role.kubernetes.io/controlplane"
          operator: "Exists"
          effect: "NoSchedule"
      containers:
        - name: csi-provisioner
          image: mcr.microsoft.com/oss/kubernetes-csi/csi-provisioner:v3.1.0
          args:
            - "-v=2"
            - "--csi-address=$(ADDRESS)"
            - "--leader-election"
            - "--leader-election-namespace=kube-system"
            - "--timeout=300s"
            - "--extra-create-metadata=true"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          volumeMounts:
            - mountPath: /csi
              name: socket-dir
          resources:
            limits:
              memory: 500Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: csi-attacher
          image: mcr.microsoft.com/oss/kubernetes-csi/csi-attacher:v3.4.0
          args:
            - "-v=2"
            - "-csi-address=$(ADDRESS)"
            - "-timeout=120s"
            - "--leader-election"
            - "--leader-election-namespace=kube-system"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          volumeMounts:
            - mountPath: /csi
              name: socket-dir
          resources:
            limits:
              memory: 500Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: csi-snapshotter
          image: mcr.microsoft.com/oss/kubernetes-csi/csi-snapshotter:v5.0.1
          args:
            - "-v=2"
            - "-csi-address=$(ADDRESS)"
            - "--leader-election"
            - "--leader-election-namespace=kube-system"
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
          resources:
            limits:
              memory: 100Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: csi-resizer
          image: mcr.microsoft.com/oss/kubernetes-csi/csi-resizer:v1.4.0
          args:
            - "-csi-address=$(ADDRESS)"
            - "-v=2"
            - "--leader-election"
            - "--leader-election-namespace=kube-system"
            - '-handle-volume-inuse-error=false'
            - '-feature-gates=RecoverVolumeExpansionFailure=true'
            - '-timeout=120s'
          env:
            - name: ADDRESS
              value: /csi/csi.sock
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
          resources:
            limits:
              memory: 500Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: liveness-probe
          image: mcr.microsoft.com/oss/kubernetes-csi/livenessprobe:v2.5.0
          args:
            - --csi-address=/csi/csi.sock
            - --probe-timeout=3s
            - --health-port=29612
            - --v=2
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
          resources:
            limits:
              memory: 100Mi
            requests:
              cpu: 10m
              memory: 20Mi
        - name: azurefile
          image: mcr.microsoft.com/k8s/csi/azurefile-csi:v1.15.0
          imagePullPolicy: IfNotPresent
          args:
            - "--v=5"
            - "--endpoint=$(CSI_ENDPOINT)"
            - "--metrics-address=0.0.0.0:29614"
            - "--user-agent-suffix=OSS-kubectl"
          ports:
            - containerPort: 29612
              name: healthz
              protocol: TCP
            - containerPort: 29614
              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
          volumeMounts:
            - mountPath: /csi
              name: socket-dir
            - mountPath: /etc/kubernetes/
              name: azure-cred
          resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 10m
              memory: 20Mi
      volumes:
        - name: socket-dir
          emptyDir: {}
        - name: azure-cred
          hostPath:
            path: /etc/kubernetes/
            type: DirectoryOrCreate
