apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "eddi.fullname" . }}
  labels:
    {{- include "eddi.labels" . | nindent 4 }}
    app.kubernetes.io/component: server
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.eddi.replicas }}
  {{- end }}
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      {{- include "eddi.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: server
  template:
    metadata:
      labels:
        {{- include "eddi.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: server
      {{- with .Values.eddi.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      {{- if .Values.serviceAccount.create }}
      serviceAccountName: {{ include "eddi.serviceAccountName" . }}
      {{- end }}
      securityContext:
        runAsNonRoot: true
        runAsUser: 185
        runAsGroup: 185
        fsGroup: 185
      terminationGracePeriodSeconds: 30
      containers:
        - name: eddi
          image: "{{ .Values.eddi.image.repository }}:{{ .Values.eddi.image.tag }}"
          imagePullPolicy: {{ .Values.eddi.image.pullPolicy }}
          ports:
            - containerPort: 7070
              name: http
              protocol: TCP
          envFrom:
            - configMapRef:
                name: {{ include "eddi.fullname" . }}-config
            - secretRef:
                name: {{ include "eddi.fullname" . }}-secrets
            {{- if .Values.postgres.enabled }}
            - secretRef:
                name: {{ include "eddi.fullname" . }}-postgres
            {{- end }}
          startupProbe:
            httpGet:
              path: /q/health/ready
              port: http
            failureThreshold: 30
            periodSeconds: 2
          livenessProbe:
            httpGet:
              path: /q/health/live
              port: http
            initialDelaySeconds: 5
            periodSeconds: 15
            timeoutSeconds: 3
          readinessProbe:
            httpGet:
              path: /q/health/ready
              port: http
            initialDelaySeconds: 5
            periodSeconds: 5
            timeoutSeconds: 3
          resources:
            {{- toYaml .Values.eddi.resources | nindent 12 }}
