# grafana_charts_deployment-ingester.yaml
{{- if eq .Values.ingester.kind "Deployment"}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "loki.ingesterFullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "loki.ingesterLabels" . | nindent 4 }}
    app.kubernetes.io/part-of: memberlist
  {{- with .Values.loki.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
{{- if not .Values.ingester.autoscaling.enabled }}
  replicas: {{ .Values.ingester.replicas }}
{{- end }}
  strategy:
    rollingUpdate:
      maxSurge: {{ .Values.ingester.maxSurge }}
      maxUnavailable: 1
  revisionHistoryLimit: {{ .Values.loki.revisionHistoryLimit }}
  selector:
    matchLabels:
      {{- include "loki.ingesterSelectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        {{- include "loki.config.checksum" . | nindent 8 }}
        {{- with .Values.loki.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- with .Values.ingester.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      labels:
        {{- include "loki.ingesterSelectorLabels" . | nindent 8 }}
        app.kubernetes.io/part-of: memberlist
        {{- with .Values.loki.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- with .Values.ingester.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }}
      {{- with .Values.ingester.topologySpreadConstraints }}
      topologySpreadConstraints:
        {{- tpl . $ | nindent 8 }}
      {{- end }}
      {{- end }}
      serviceAccountName: {{ include "loki.serviceAccountName" . }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.ingester.hostAliases }}
      hostAliases:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- include "loki.ingesterPriorityClassName" . | nindent 6 }}
      securityContext:
        {{- toYaml .Values.loki.podSecurityContext | nindent 8 }}
      terminationGracePeriodSeconds: {{ .Values.ingester.terminationGracePeriodSeconds }}
      {{- with .Values.ingester.initContainers }}
      initContainers:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: ingester
          image: {{ include "loki.ingesterImage" . }}
          imagePullPolicy: {{ .Values.loki.image.pullPolicy }}
          {{- if or .Values.loki.command .Values.ingester.command }}
          command:
            - {{ coalesce .Values.ingester.command .Values.loki.command | quote }}
          {{- end }}
          args:
            - -config.file=/etc/loki/config/config.yaml
            - -target=ingester
            {{- with .Values.ingester.extraArgs }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          ports:
            - name: http
              containerPort: 3100
              protocol: TCP
            - name: grpc
              containerPort: 9095
              protocol: TCP
            - name: http-memberlist
              containerPort: 7946
              protocol: TCP
          {{- with .Values.ingester.extraEnv }}
          env:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.ingester.extraEnvFrom }}
          envFrom:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          securityContext:
            {{- toYaml .Values.loki.containerSecurityContext | nindent 12 }}
          {{- include "loki.ingester.readinessProbe" . | nindent 10 }}
          {{- include "loki.ingester.livenessProbe" . | nindent 10 }}
          volumeMounts:
            - name: config
              mountPath: /etc/loki/config
            - name: runtime-config
              mountPath: /var/{{ include "loki.name" . }}-runtime
            - name: data
              mountPath: /var/loki
            {{- with .Values.ingester.extraVolumeMounts }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          {{- with .Values.ingester.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.ingester.lifecycle }}
          lifecycle:
            {{- toYaml . | nindent 12 }}
          {{- end }}
        {{- if .Values.ingester.extraContainers }}
        {{- toYaml .Values.ingester.extraContainers | nindent 8}}
        {{- end }}
      {{- with .Values.ingester.affinity }}
      affinity:
        {{- tpl . $ | nindent 8 }}
      {{- end }}
      {{- with .Values.ingester.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.ingester.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - name: config
          {{- if .Values.loki.existingSecretForConfig }}
          secret:
            secretName: {{ .Values.loki.existingSecretForConfig }}
          {{- else if .Values.loki.configAsSecret }}
          secret:
            secretName: {{ include "loki.fullname" . }}-config
          {{- else }}
          configMap:
            name: {{ include "loki.fullname" . }}
          {{- end }}
        - name: runtime-config
          configMap:
            name: {{ template "loki.fullname" . }}-runtime
        {{- with .Values.ingester.extraVolumes }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        - name: data
        {{- if .Values.ingester.persistence.inMemory }}
          emptyDir:
            medium: Memory
        {{- if .Values.ingester.persistence.size }}
            sizeLimit: {{ .Values.ingester.persistence.size }}
        {{- end }}
        {{- else }}
          emptyDir: {}
        {{- end }}
{{- end }}