{{- if and (include "parse.host" .) .Values.dashboard.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "parse.fullname" . }}-dashboard
  labels: {{ include "parse.labels" . | nindent 4 }}
    app.kubernetes.io/component: dashboard
spec:
  selector:
    matchLabels: {{ include "parse.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: dashboard
  replicas: 1
  template:
    metadata:
      labels: {{ include "parse.labels" . | nindent 8 }}
        app.kubernetes.io/component: dashboard
    spec:
      {{- if .Values.dashboard.affinity }}
      affinity: {{- include "parse.tplValue" (dict "value" .Values.dashboard.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.dashboard.nodeSelector }}
      nodeSelector: {{- include "parse.tplValue" (dict "value" .Values.dashboard.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.dashboard.tolerations }}
      tolerations: {{- include "parse.tplValue" (dict "value" .Values.dashboard.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.dashboard.securityContext.enabled }}
      securityContext:
        fsGroup: {{ .Values.dashboard.securityContext.fsGroup }}
        runAsUser: {{ .Values.dashboard.securityContext.runAsUser }}
      {{- end }}
{{- include "parse.imagePullSecrets" . | indent 6 }}
      containers:
        - name: parse-dashboard
          image: {{ include "parse.dashboard.image" . }}
          imagePullPolicy: {{ .Values.dashboard.image.pullPolicy | quote }}
          env:
            - name: PARSE_DASHBOARD_USER
              value: {{ .Values.dashboard.username }}
            - name: PARSE_DASHBOARD_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "parse.fullname" . }}
                  key: parse-dashboard-password
            - name: PARSE_HOST
              value: {{ include "parse.host" . | quote }}
            - name: PARSE_USE_HOSTNAME
              value: {{ ternary "yes" "no" .Values.ingress.enabled | quote }}
            - name: PARSE_PORT_NUMBER
              value: {{ include "parse.external-port" . | quote }}
            - name: PARSE_PROTOCOL
              value: {{ .Values.dashboard.parseServerUrlProtocol | quote }}
            - name: PARSE_APP_ID
              value: {{ .Values.server.appId | quote }}
            - name: PARSE_MASTER_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "parse.fullname" . }}
                  key: master-key
            - name: PARSE_DASHBOARD_APP_NAME
              value: {{ .Values.dashboard.appName | quote }}
            {{- if .Values.dashboard.extraEnvVars }}
              {{- include "parse.tplValue" ( dict "value" .Values.dashboard.extraEnvVars "context" $ ) | nindent 12 }}
            {{- end }}
          {{- if or .Values.dashboard.extraEnvVarsCM .Values.dashboard.extraEnvVarsSecret }}
          envFrom:
            {{- if .Values.dashboard.extraEnvVarsCM }}
            - configMapRef:
                name: {{ include "parse.tplValue" ( dict "value" .Values.dashboard.extraEnvVarsCM "context" $ ) }}
            {{- end }}
            {{- if .Values.dashboard.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "parse.tplValue" ( dict "value" .Values.dashboard.extraEnvVarsSecret "context" $ ) }}
            {{- end }}
          {{- end }}
          ports:
            - name: dashboard-http
              containerPort: 4040
          {{- if and .Values.dashboard.livenessProbe.enabled }}
          livenessProbe:
            httpGet:
              path: /
              port: dashboard-http
            initialDelaySeconds: {{ .Values.dashboard.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.dashboard.livenessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.dashboard.livenessProbe.timeoutSeconds }}
            successThreshold: {{ .Values.dashboard.livenessProbe.successThreshold }}
            failureThreshold: {{ .Values.dashboard.livenessProbe.failureThreshold }}
          {{- end }}
          {{- if and .Values.dashboard.readinessProbe.enabled }}
          readinessProbe:
            httpGet:
              path: /
              port: dashboard-http
            initialDelaySeconds: {{ .Values.dashboard.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.dashboard.readinessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.dashboard.readinessProbe.timeoutSeconds }}
            successThreshold: {{ .Values.dashboard.readinessProbe.successThreshold }}
            failureThreshold: {{ .Values.dashboard.readinessProbe.failureThreshold }}
          {{- end }}
          {{- if .Values.dashboard.resources }}
          resources: {{- toYaml .Values.dashboard.resources | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: parse-dashboard-data
              mountPath: /bitnami/parse-dashboard
      volumes:
        - name: parse-dashboard-data
          emptyDir: {}
{{- end -}}
