apiVersion: {{ template "deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ template "seq.fullname" . }}
  labels:
    app: {{ template "seq.name" . }}
    chart: {{ template "seq.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  selector:
    matchLabels:
      app: {{ template "seq.name" . }}
      release: {{ .Release.Name }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: {{ template "seq.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: "ACCEPT_EULA"
              value: "{{ .Values.acceptEULA }}"
{{- if .Values.baseURI }}
            - name: "BASE_URI"
              value: "{{ .Values.baseURI }}"
{{- end }}
            - name: "SEQ_CACHE_SYSTEMRAMTARGET"
              value: "{{ .Values.cache.targetSize }}"
          ports:
            - name: ingestion
              containerPort: 5341
              protocol: TCP
            - name: ui
              containerPort: 80
              protocol: TCP
{{- if .Values.podSecurityPolicy.create }}
          securityContext:
            runAsUser: 0
            capabilities:
              add:
                - NET_BIND_SERVICE
{{- end }}
{{- if .Values.livenessProbe.enabled }}
          livenessProbe:
            httpGet:
              path: /
              port: ui
            failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
            initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
            successThreshold: {{ .Values.livenessProbe.successThreshold }}
            timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
          readinessProbe:
            httpGet:
              path: /
              port: ui
            failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
            initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
            successThreshold: {{ .Values.readinessProbe.successThreshold }}
            timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
{{- end }}
{{- if .Values.startupProbe.enabled }}
          startupProbe:
            httpGet:
              path: /
              port: ui
            failureThreshold: {{ .Values.startupProbe.failureThreshold }}
            periodSeconds: {{ .Values.startupProbe.periodSeconds }}
{{- end }}
          volumeMounts:
          - name: seq-data
            mountPath: {{ .Values.persistence.path }}
            subPath: {{ .Values.persistence.subPath }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
{{- if .Values.gelf.enabled }}
        - name: {{ .Chart.Name }}-gelf
          image: "{{ .Values.gelf.image.repository }}:{{ .Values.gelf.image.tag }}"
          imagePullPolicy: {{ .Values.gelf.image.pullPolicy }}
          env:
            - name: "SEQ_ADDRESS"
              value: "http://{{ template "seq.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.ingestion.service.port }}"
            - name: "SEQ_API_KEY"
              value: "{{ .Values.gelf.apiKey }}"
            - name: "GELF_ADDRESS"
              value: "{{ .Values.gelf.service.protocol | lower }}://0.0.0.0:12201"
            - name: "GELF_ENABLE_DIAGNOSTICS"
              value: "True"
          ports:
            - name: gelf
              containerPort: 12201
              protocol: {{ .Values.gelf.service.protocol }}
          securityContext:
            runAsUser: 0
            capabilities:
              add:
                - NET_BIND_SERVICE
{{- end }}
{{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
      serviceAccountName: "{{ template "seq.serviceAccountName" . }}"
      volumes:
      - name: seq-data
{{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim | default (include "seq.fullname" .) }}
{{- else }}
        emptyDir: {}
{{- end -}}
