{{- if not .Values.replicaSet.enabled }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "mongodb.fullname" . }}
  labels:
    app: {{ template "mongodb.name" . }}
    chart: {{ template "mongodb.chart" . }}
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  template:
    metadata:
      labels:
        app: {{ template "mongodb.name" . }}
        release: "{{ .Release.Name }}"
        chart: {{ template "mongodb.chart" . }}
    spec:
      {{- if .Values.securityContext.enabled }}
      securityContext:
        fsGroup: {{ .Values.securityContext.fsGroup }}
        runAsUser: {{ .Values.securityContext.runAsUser }}
      {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      {{- end }}
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
      {{- end}}
      {{- end }}
      containers:
      - name: {{ template "mongodb.fullname" . }}
        image: {{ template "mongodb.image" . }}
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        env:
        {{- if .Values.usePassword }}
        - name: MONGODB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "mongodb.fullname" . }}
              key: mongodb-root-password
        {{- end }}
        - name: MONGODB_USERNAME
          value: {{ default "" .Values.mongodbUsername | quote }}
        {{- if and .Values.mongodbUsername .Values.mongodbDatabase }}
        - name: MONGODB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "mongodb.fullname" . }}
              key: mongodb-password
        {{- end }}
        - name: MONGODB_DATABASE
          value: {{ default "" .Values.mongodbDatabase | quote }}
        - name: MONGODB_EXTRA_FLAGS
          value: {{ default "" .Values.mongodbExtraFlags | join " " }}
        ports:
        - name: mongodb
          containerPort: 27017
        {{- if .Values.livenessProbe.enabled }}
        livenessProbe:
          exec:
            command:
            - mongo
            - --eval
            - "db.adminCommand('ping')"
          initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
          successThreshold: {{ .Values.livenessProbe.successThreshold }}
          failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
        {{- end }}
        {{- if .Values.readinessProbe.enabled }}
        readinessProbe:
          exec:
            command:
            - mongo
            - --eval
            - "db.adminCommand('ping')"
          initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
          successThreshold: {{ .Values.readinessProbe.successThreshold }}
          failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
        {{- end }}
        volumeMounts:
        - name: data
          mountPath: /bitnami/mongodb
        {{- if .Values.configmap }}
        - name: config
          mountPath: /opt/bitnami/mongodb/conf/mongodb.conf
          subPath: mongodb.conf
        {{- end }}
        resources:
{{ toYaml .Values.resources | indent 10 }}
      volumes:
      - name: data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ template "mongodb.fullname" . }}{{- end }}

      {{- else }}
        emptyDir: {}
      {{- end -}}
      {{- if .Values.configmap }}
      - name: config
        configMap:
          name: {{ template "mongodb.fullname" . }}
      {{- end }}
 {{- end -}}
