# grafana_charts_statefulset-ingester.yaml
{{- $dict := dict "ctx" . "component" "ingester" "memberlist" true -}}
{{- $zonesMap := include "ingester.zoneAwareReplicationMap" $dict | fromYaml -}}
{{- range $zoneName, $rolloutZone := $zonesMap -}}
{{- with $ -}}
{{- $_ := set $dict "rolloutZoneName" $zoneName -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ template "ingester.resourceName" $dict }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "ingester.labels" $dict | indent 4 }}
  {{- if .Values.ingester.zoneAwareReplication.enabled }}
  annotations:
    {{- include "ingester.Annotations" $dict | nindent 4}}
    {{- with $rolloutZone.annotations }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- else }}
  {{- with .Values.ingester.annotations }}
  annotations:
  {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- end }}
spec:
  {{- if not .Values.ingester.autoscaling.enabled }}
  replicas: {{ $rolloutZone.replicas }}
  {{- end }}
  revisionHistoryLimit: {{ .Values.tempo.revisionHistoryLimit }}
  selector:
    matchLabels:
      {{- include "ingester.selectorLabels" $dict | nindent 6}}
  serviceName: ingester
  podManagementPolicy: Parallel
  updateStrategy:
    {{- if .Values.ingester.zoneAwareReplication.enabled }}
    type: OnDelete
    {{- else }}
    {{- toYaml .Values.ingester.statefulStrategy | nindent 4 }}
    {{- end }}
  template:
    metadata:
      labels:
        {{- include "ingester.podLabels" $dict | nindent 8 }}
        {{- with .Values.tempo.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap-tempo.yaml") . | sha256sum }}
        {{- if .Values.ingester.persistence.enabled }}
        storage/size: {{ .Values.ingester.persistence.size | quote }}
        {{- end }}
        {{- with .Values.tempo.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- with .Values.ingester.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- with $rolloutZone.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- if or (.Values.ingester.priorityClassName) (.Values.global.priorityClassName) }}
      priorityClassName: {{ default .Values.ingester.priorityClassName .Values.global.priorityClassName }}
      {{- end }}
      serviceAccountName: {{ include "tempo.serviceAccountName" . }}
      {{- with .Values.tempo.podSecurityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      enableServiceLinks: false
      {{- include "tempo.ingesterImagePullSecrets" . | nindent 6 -}}
      {{- with .Values.ingester.hostAliases }}
      hostAliases:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      initContainers:
        {{- toYaml .Values.ingester.initContainers | nindent 8 }}
      containers:
        - args:
            - -target=ingester
            - -config.file=/conf/tempo.yaml
            {{- if ne $zoneName ""}}
            - -ingester.availability-zone={{ $zoneName }}
            {{- end }}
            {{- with .Values.ingester.extraArgs }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
            {{- with .Values.global.extraArgs }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          image: {{ include "tempo.imageReference" $dict }}
          imagePullPolicy: {{ .Values.tempo.image.pullPolicy }}
          name: ingester
          ports:
            - name: grpc
              containerPort: 9095
            - name: http-memberlist
              containerPort: {{ include "tempo.memberlistBindPort" . }}
            - name: http-metrics
              containerPort: 3200
          {{- if or .Values.global.extraEnv .Values.ingester.extraEnv }}
          env:
            {{- with .Values.global.extraEnv }}
              {{- toYaml . | nindent 12 }}
            {{- end }}
            {{- with .Values.ingester.extraEnv }}
              {{- toYaml . | nindent 12 }}
            {{- end }}
          {{- end }}
          {{- if or .Values.global.extraEnvFrom .Values.ingester.extraEnvFrom }}
          envFrom:
            {{- with .Values.global.extraEnvFrom }}
              {{- toYaml . | nindent 12 }}
            {{- end }}
            {{- with .Values.ingester.extraEnvFrom }}
              {{- toYaml . | nindent 12 }}
            {{- end }}
          {{- end }}
          livenessProbe:
            {{- toYaml .Values.tempo.livenessProbe | nindent 12 }}
          readinessProbe:
            {{- toYaml .Values.tempo.readinessProbe | nindent 12 }}
          resources:
            {{- toYaml .Values.ingester.resources | nindent 12 }}
          {{- with .Values.tempo.securityContext }}
          securityContext:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          volumeMounts:
            - mountPath: /conf
              name: config
            - mountPath: /runtime-config
              name: runtime-config
            - mountPath: /var/tempo
              name: data
            {{- if .Values.enterprise.enabled }}
            - name: license
              mountPath: /license
            {{- end }}
            {{- with .Values.ingester.extraVolumeMounts }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
      terminationGracePeriodSeconds: {{ .Values.ingester.terminationGracePeriodSeconds }}
      {{- if semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version }}
      {{- with .Values.ingester.topologySpreadConstraints }}
      topologySpreadConstraints:
        {{- tpl . $ | nindent 8 }}
      {{- end }}
      {{- end }}
      {{- if eq $zoneName ""}}
      {{- with $rolloutZone.affinity }}
      affinity:
        {{- tpl . $ | nindent 8 }}
      {{- end }}
      {{- end }}
      {{- if ne $zoneName "" }}
      {{- with $rolloutZone.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- end }}
      {{- with $rolloutZone.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.ingester.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - name: config
          {{- include "tempo.configVolume" . | nindent 10 }}
        - name: runtime-config
          {{- include "tempo.runtimeVolume" . | nindent 10 }}
        {{- if .Values.enterprise.enabled }}
        - name: license
          secret:
            secretName: {{ tpl .Values.license.secretName . }}
        {{- end }}
        {{- with .Values.ingester.extraVolumes }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
  {{- if not .Values.ingester.persistence.enabled }}
        - name: data
          emptyDir: {}
  {{- else if .Values.ingester.persistence.inMemory }}
        - name: data
        {{- if .Values.ingester.persistence.inMemory }}
          emptyDir:
            medium: Memory
        {{- end }}
        {{- if .Values.ingester.persistence.size }}
            sizeLimit: {{ .Values.ingester.persistence.size }}
        {{- end }}
  {{- else }}
  {{- if .Values.ingester.persistentVolumeClaimRetentionPolicy.enabled }}
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: {{ .Values.ingester.persistentVolumeClaimRetentionPolicy.whenDeleted }}
    whenScaled: {{ .Values.ingester.persistentVolumeClaimRetentionPolicy.whenScaled }}
  {{- end }}
  volumeClaimTemplates:
    - apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        {{- with .Values.ingester.persistence.annotations }}
        annotations:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        {{- with .Values.ingester.persistence.labels }}
        labels:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        name: data
      spec:
        {{- $storageClass := coalesce $rolloutZone.storageClass .Values.ingester.persistence.storageClass .Values.global.storageClass }}
        {{- if eq $storageClass "-" }}
        storageClassName: ""
        {{- else if $storageClass }}
        storageClassName: {{ $storageClass }}
        {{- end }}
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: {{ .Values.ingester.persistence.size | quote }}
  {{- end }}
---
{{ end }}
{{ end }}