{{- if eq .Values.mode "standalone" }}
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "minio.fullname" . }}
  labels:
    app: {{ template "minio.name" . }}
    chart: {{ template "minio.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  {{- if .Values.nasgateway.enabled }}
  replicas: {{ .Values.nasgateway.replicas }}
  {{- end }}
  selector:
    matchLabels:
      app: {{ template "minio.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      name: {{ template "minio.fullname" . }}
      labels:
        app: {{ template "minio.name" . }}
        release: {{ .Release.Name }}
    spec:
  {{- if .Values.priorityClassName }}
      priorityClassName: "{{ .Values.priorityClassName }}"
  {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- if .Values.azuregateway.enabled }}
          command: [ "/bin/sh", 
          "-ce", 
          "cp /tmp/config.json {{ .Values.configPath }} && 
          /usr/bin/docker-entrypoint.sh minio -C {{ .Values.configPath }} gateway azure"]
          {{- else }}
          {{- if .Values.gcsgateway.enabled }}
          command: [ "/bin/sh", 
          "-ce", 
          "cp /tmp/config.json {{ .Values.configPath }} && 
          /usr/bin/docker-entrypoint.sh minio -C {{ .Values.configPath }} gateway gcs {{ .Values.gcsgateway.projectId }}"]
          {{- else }}
          {{- if .Values.nasgateway.enabled }}
          command: [ "/bin/sh", 
          "-ce", 
          "cp /tmp/config.json {{ .Values.configPath }} && 
          /usr/bin/docker-entrypoint.sh minio -C {{ .Values.configPath }} gateway nas {{ .Values.mountPath }}"]
          {{- else }}
          command: [ "/bin/sh", 
          "-ce", 
          "cp /tmp/config.json {{ .Values.configPath }} && 
          /usr/bin/docker-entrypoint.sh minio -C {{ .Values.configPath }} server {{ .Values.mountPath }}" ]
          {{- end }}
          {{- end }}
          {{- end }}
          volumeMounts:
            - name: export
              mountPath: {{ .Values.mountPath }}
              {{- if and .Values.persistence.enabled .Values.persistence.subPath }}
              subPath: "{{ .Values.persistence.subPath }}"
              {{- end }}
            {{- if .Values.gcsgateway.enabled }}
            - name: minio-user
              mountPath: "/etc/credentials"
              readOnly: true
            {{- end }}
            - name: minio-server-config
              mountPath: "/tmp/config.json"
              subPath: config.json
            - name: minio-config-dir
              mountPath: {{ .Values.configPath }}
          ports:
            - name: service
              containerPort: 9000
          env:
            - name: MINIO_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ template "minio.fullname" . }}
                  key: accesskey
            - name: MINIO_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ template "minio.fullname" . }}
                  key: secretkey
            {{- if .Values.gcsgateway.enabled }}
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: "/etc/credentials/gcs_key.json"
            {{- end }}
          livenessProbe:
            tcpSocket:
              port: 9000
            timeoutSeconds: 1
          resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
      volumes:
        - name: export
        {{- if .Values.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ .Values.persistence.existingClaim | default (include "minio.fullname" .) }}
        {{- else }}
          emptyDir: {}
        {{- end }}
        - name: minio-server-config
          configMap:
            name: {{ template "minio.fullname" . }}
        - name: minio-user
          secret:
            secretName: {{ template "minio.fullname" . }}
        - name: minio-config-dir
          emptyDir: {}
{{- end }}
