apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "focalboard.fullname" . }}
  labels:
    {{- include "focalboard.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  strategy:
    type: {{ .Values.strategy }}
  selector:
    matchLabels:
      {{- include "focalboard.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "focalboard.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "focalboard.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          startupProbe:
            httpGet:
              path: /
              port: http
            periodSeconds: 3
            failureThreshold: 20
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: fbdata
            mountPath: /opt/focalboard/data
          - name: fbconfig
            mountPath: /opt/focalboard/config.json
            subPath: config
          env:
            - name: FOCALBOARD_SERVERROOT
              valueFrom:
                configMapKeyRef:
                  name: {{ include "focalboard.fullname" . }}
                  key: serverRoot
            - name: FOCALBOARD_PORT
              valueFrom:
                configMapKeyRef:
                  name: {{ include "focalboard.fullname" . }}
                  key: port
      volumes:
      - name: fbdata
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ template "focalboard.fullname" . }}-pvc{{- end }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      - name: fbconfig
        configMap:
          name: {{ include "focalboard.fullname" . }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}