apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "infisical.mongodb.fullname" . }}
  labels:
    {{- include "infisical.mongodb.labels" . | nindent 4 }}
spec:
  replicas: 1 # Cannot be scaled. To scale, you must set up Stateful Set
  selector:
    matchLabels:
      {{- include "infisical.mongodb.matchLabels" . | nindent 6 }}
  template:
    metadata: 
      labels:
        {{- include "infisical.mongodb.matchLabels" . | nindent 8 }}
      {{- with .Values.mongodb.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      containers:
      - name: {{ template "infisical.name" . }}-{{ .Values.mongodb.name }}  
        image: "{{ .Values.mongodb.image.repository }}:{{ .Values.mongodb.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: {{ .Values.mongodb.image.pullPolicy }}
        ports: 
        - containerPort: 27017
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          value: root
        - name: MONGO_INITDB_ROOT_PASSWORD
          value: root
---
apiVersion: v1
kind: Service 
metadata:
  name: {{ include "infisical.mongodb.fullname" . }}
  labels:
    {{- include "infisical.mongodb.labels" . | nindent 4 }}
  {{- with .Values.mongodb.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  selector:
    {{- include "infisical.mongodb.matchLabels" . | nindent 8 }}
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017 # container port 
