apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mattermost-team-edition.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
spec:
  replicas: 1
  strategy:
    type: Recreate
    rollingUpdate: null
  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/managed-by: {{ .Release.Service }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/secret-config.yaml") . | sha256sum }}
      labels:
        app.kubernetes.io/name: {{ include "mattermost-team-edition.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/managed-by: {{ .Release.Service }}
        helm.sh/chart: {{ include "mattermost-team-edition.chart" . }}
    spec:
      initContainers:
      {{- if not .Values.externalDB.enabled }}
      - name: "init-mysql"
        image: "{{ .Values.initContainerImage.repository }}:{{ .Values.initContainerImage.tag }}"
        imagePullPolicy: {{ .Values.initContainerImage.imagePullPolicy }}
        command: ["sh", "-c", "until curl --max-time 5 http://{{ .Release.Name }}-mysql:3306; do echo waiting for {{ .Release.Name }}-mysql; sleep 5; done;"]
      {{- end }}
      {{- if .Values.extraInitContainers }}
      {{- .Values.extraInitContainers | toYaml | nindent 6 }}
      {{- end }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.imagePullPolicy }}
        env:
        {{- if .Values.extraEnvVars }}
          {{- .Values.extraEnvVars | toYaml | nindent 10 }}
        {{- end }}
        ports:
        - name: http
          containerPort: {{ .Values.service.internalPort }}
          protocol: TCP
        livenessProbe:
          initialDelaySeconds: 90
          timeoutSeconds: 5
          periodSeconds: 15
          httpGet:
            path: /api/v4/system/ping
            port: http
        readinessProbe:
          initialDelaySeconds: 15
          timeoutSeconds: 5
          periodSeconds: 15
          httpGet:
            path: /api/v4/system/ping
            port: http
        volumeMounts:
        - mountPath: /mattermost/config/config.json
          name: config-json
          subPath: config.json
        - mountPath: /mattermost/data
          name: mattermost-data
        resources:
          {{- .Values.resources | toYaml | nindent 12 }}
      volumes:
      - name: config-json
        secret:
          secretName: {{ include "mattermost-team-edition.fullname" . }}-config-json
      - name: mattermost-data
      {{ if .Values.persistence.data.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.data.existingClaim | default (include "mattermost-team-edition.fullname" .) }}
      {{ else }}
        emptyDir: {}
      {{ end }}
