kind: Deployment
apiVersion: apps/v1
metadata:
  name: csi-gce-pd-controller
  namespace: {{ .Release.Namespace }}
spec:
  replicas: {{ .Values.csiController.replicas }}
  selector:
    matchLabels:
      app: gcp-compute-persistent-disk-csi-driver
  template:
    metadata:
      labels:
        app: gcp-compute-persistent-disk-csi-driver
    spec:
{{- if .Values.csiController.runOnControlPlane }}
      tolerations:
        - effect: NoSchedule
          key: node-role.kubernetes.io/control-plane
          operator: Exists
        - effect: NoSchedule
          key: node-role.kubernetes.io/master
          operator: Exists
        - effect: NoSchedule
          key: node.cloudprovider.kubernetes.io/uninitialized
          operator: Exists
        - effect: NoSchedule
          key: node.kubernetes.io/not-ready
          operator: Exists
{{- end }}
      nodeSelector:
        kubernetes.io/os: linux
{{- if .Values.csiController.runOnControlPlane }}
        node-role.kubernetes.io/control-plane: ""
{{- end }}
      serviceAccountName: csi-gce-pd-controller-sa
      priorityClassName: csi-gce-pd-controller
      containers:
        - name: csi-provisioner
          image: {{ .Values.image.csiProvisioner.repo }}:{{ .Values.image.csiProvisioner.tag }}
          imagePullPolicy: {{ .Values.image.csiProvisioner.pullPolicy }}
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--feature-gates=Topology=true"
            - "--http-endpoint=:22011"
            - "--leader-election-namespace=$(PDCSI_NAMESPACE)"
            - "--timeout=250s"
            - "--extra-create-metadata"
          # - "--run-controller-service=false"  # disable the controller service of the CSI driver
          # - "--run-node-service=false"        # disable the node service of the CSI driver
            - "--leader-election"
            - "--default-fstype=ext4"
            - "--controller-publish-readonly=true"
          env:
            - name: PDCSI_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - containerPort: 22011
              name: http-endpoint
              protocol: TCP
          livenessProbe:
            failureThreshold: 1
            httpGet:
              path: /healthz/leader-election
              port: http-endpoint
            initialDelaySeconds: 10
            timeoutSeconds: 10
            periodSeconds: 20
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
        - name: csi-attacher
          image: {{ .Values.image.csiAttacher.repo }}:{{ .Values.image.csiAttacher.tag }}
          imagePullPolicy: {{ .Values.image.csiAttacher.pullPolicy }}
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--http-endpoint=:22012"
            - "--leader-election"
            - "--leader-election-namespace=$(PDCSI_NAMESPACE)"
            - "--timeout=250s"
          env:
            - name: PDCSI_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - containerPort: 22012
              name: http-endpoint
              protocol: TCP
          livenessProbe:
            failureThreshold: 1
            httpGet:
              path: /healthz/leader-election
              port: http-endpoint
            initialDelaySeconds: 10
            timeoutSeconds: 10
            periodSeconds: 20
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
        - name: csi-resizer
          image: {{ .Values.image.csiResizer.repo }}:{{ .Values.image.csiResizer.tag }}
          imagePullPolicy: {{ .Values.image.csiResizer.pullPolicy }}
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--http-endpoint=:22013"
            - "--leader-election"
            - "--leader-election-namespace=$(PDCSI_NAMESPACE)"
            - "--handle-volume-inuse-error=false"
          env:
            - name: PDCSI_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - containerPort: 22013
              name: http-endpoint
              protocol: TCP
          livenessProbe:
            failureThreshold: 1
            httpGet:
              path: /healthz/leader-election
              port: http-endpoint
            initialDelaySeconds: 10
            timeoutSeconds: 10
            periodSeconds: 20
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
        - name: csi-snapshotter
          image: {{ .Values.image.csiSnapshotter.repo }}:{{ .Values.image.csiSnapshotter.tag }}
          imagePullPolicy: {{ .Values.image.csiSnapshotter.pullPolicy }}
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--metrics-address=:22014"
            - "--leader-election"
            - "--leader-election-namespace=$(PDCSI_NAMESPACE)"
            - "--timeout=300s"
          env:
            - name: PDCSI_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
        - name: gce-pd-driver
          # Don't change base image without changing pdImagePlaceholder in
          # test/k8s-integration/main.go
          image: {{ .Values.image.gcepdDriver.repo }}:{{ .Values.image.gcepdDriver.tag }}
          imagePullPolicy: {{ .Values.image.gcepdDriver.pullPolicy }}
          args:
            - "--v=5"
            - "--endpoint=unix:/csi/csi.sock"
          env:
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: "/etc/cloud-sa/key.json"
          volumeMounts:
            - name: socket-dir
              mountPath: /csi
            - name: cloud-sa-volume
              readOnly: true
              mountPath: "/etc/cloud-sa"
      volumes:
        - name: socket-dir
          emptyDir: {}
        - name: cloud-sa-volume
          secret:
            secretName: gcekey
