{{- if .Values.microservices.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-presence
  labels:
    app.kubernetes.io/name: {{ include "rocketchat.name" . }}
    helm.sh/chart: {{ include "rocketchat.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    {{- if .Values.deploymentLabels }}
      {{- toYaml .Values.deploymentLabels | nindent 4 }}
    {{- end }}
spec:
  replicas: {{ .Values.microservices.presence.replicas }}
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ .Release.Name }}-presence
      app.kubernetes.io/instance: {{ .Release.Name }}
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ .Release.Name }}-presence
        app.kubernetes.io/instance: {{ .Release.Name }}
        {{- if .Values.podLabels }}
          {{- toYaml .Values.podLabels | nindent 8 }}
        {{- end }}
      annotations:
    {{ include "rocketchat.annotations" (dict "name" "presence" "context" $) | indent 8 }}
    spec:
      tolerations:
        {{ include "rocketchat.tolerations" (dict "name" "presence" "context" $) | indent 8 }}
      nodeSelector:
        {{ include "rocketchat.nodeSelector" (dict "name" "presence" "context" $) | indent 8 }}      
      affinity:
        {{ include "rocketchat.nodeAffinity" (dict "name" "presence" "context" $) | indent 8 }}   
      containers:
      - name: presence-service
        image: "{{ .Values.microservices.presence.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        env:
        {{- if .Values.existingMongodbSecret }}
        - name: MONGO_URL
          valueFrom:
            secretKeyRef:
              name: {{ .Values.existingMongodbSecret }}
              key: mongo-uri
        {{- else }}
        - name: MONGO_URL
          valueFrom:
            secretKeyRef:
              name: {{ template "rocketchat.fullname" . }}
              key: mongo-uri
        {{- end }}
        - name: TRANSPORTER
          value: nats://{{ .Release.Name }}-nats:4222
        - name: MOLECULER_LOG_LEVEL
          value: {{ .Values.microservices.logLevel | quote }}
        - name: HEARTBEAT_INTERVAL
          value: {{ .Values.microservices.heartbeatInterval | quote }}
        - name: HEARTBEAT_TIMEOUT
          value: {{ .Values.microservices.heartbeatTimeout | quote }}
        - name: RETRY_ENABLED
          value: 'yes'
        - name: MS_METRICS
          value: {{ .Values.prometheusScraping.enabled | default "false" | quote }}
        volumeMounts: 
        {{- if .Values.extraVolumeMounts }}
        {{- include "common.tplvalues.render" (dict "value" .Values.extraVolumeMounts "context" $) | nindent 8 }}
        {{- end }}   
        securityContext:
          {{- toYaml .Values.microservices.presence.securityContext | nindent 10 }}
        resources: {{- toYaml .Values.microservices.presence.resources | nindent 10 }}
      volumes:
      {{- if .Values.extraVolumes }}
      {{- include "common.tplvalues.render" (dict "value" .Values.extraVolumes "context" $) | nindent 6 }}
      {{- end }}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
{{- end }}

{{/* vi: ts=8 et sw=2 smarttab */}}
