{{- if eq .Values.mode "statefulset" -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "opentelemetry-collector.fullname" . }}
  labels:
    {{- include "opentelemetry-collector.labels" . | nindent 4 }}
  {{- if .Values.annotations }}
  annotations:
    {{- range $key, $value := .Values.annotations }}
    {{- printf "%s: %s" $key (tpl $value $ | quote) | nindent 4 }}
    {{- end }}
  {{- end }}
spec:
  serviceName: {{ include "opentelemetry-collector.fullname" . }}
  podManagementPolicy: {{ .Values.statefulset.podManagementPolicy }}
{{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
{{- end }}
  selector:
    matchLabels:
      {{- include "opentelemetry-collector.selectorLabels" . | nindent 6 }}
      {{- include "opentelemetry-collector.component" . | nindent 6 }}
  updateStrategy:
    type: {{ .Values.rollout.strategy }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        {{- include "opentelemetry-collector.podAnnotations" . | nindent 8 }}
      labels:
        {{- include "opentelemetry-collector.selectorLabels" . | nindent 8 }}
        {{- include "opentelemetry-collector.component" . | nindent 8 }}
        {{- include "opentelemetry-collector.podLabels" . | nindent 8 }}
    spec:
      {{- $podValues := deepCopy .Values }}
      {{- $podData := dict "Values" $podValues "configmapSuffix" "-statefulset" "isAgent" false }}
      {{- include "opentelemetry-collector.pod" ($podData | mustMergeOverwrite (deepCopy .)) | nindent 6 }}
      hostNetwork: {{ .Values.hostNetwork }}
  {{- with .Values.statefulset.volumeClaimTemplates }}
  volumeClaimTemplates:
  {{- toYaml . | nindent 2 }}
  {{- end }}
{{- end }}
