{{- if .Values.horizon.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "finaegis.fullname" . }}-horizon
  labels:
    {{- include "finaegis.labels" . | nindent 4 }}
    app.kubernetes.io/component: horizon
spec:
  {{- if not .Values.horizon.autoscaling.enabled }}
  replicas: {{ .Values.horizon.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "finaegis.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: horizon
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        {{- include "finaegis.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: horizon
    spec:
      {{- with .Values.global.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        runAsNonRoot: true
        runAsUser: 82
        fsGroup: 82
      containers:
        - name: horizon
          image: {{ include "finaegis.image" . }}-horizon
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - php
            - artisan
            - horizon
          envFrom:
            - configMapRef:
                name: {{ include "finaegis.configMapName" . }}
            {{- if .Values.externalSecrets.enabled }}
            - secretRef:
                name: {{ include "finaegis.secretName" . }}
            {{- end }}
          livenessProbe:
            {{- toYaml .Values.horizon.livenessProbe | nindent 12 }}
          resources:
            {{- toYaml .Values.horizon.resources | nindent 12 }}
          volumeMounts:
            - name: storage
              mountPath: /var/www/html/storage/logs
              subPath: logs
      volumes:
        - name: storage
          emptyDir: {}
      {{- with .Values.web.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.web.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
