{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and (.Values.receive.enabled) (.Values.receive.service.additionalHeadless) -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "thanos.receive.fullname" . }}-headless
  namespace: {{ include "common.names.namespace" . }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: receive
    {{- if eq .Values.receive.mode "dual-mode" }}
    {{- include "thanos.servicemonitor.matchLabels" . | nindent 4 -}}
    {{- end }}
  {{- if or .Values.receive.service.headless.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.receive.service.headless.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: {{ .Values.receive.service.ports.http }}
      targetPort: http
      protocol: TCP
      name: http
    - port: {{ .Values.receive.service.ports.grpc }}
      targetPort: grpc
      protocol: TCP
      name: grpc
    - port: {{ .Values.receive.service.ports.capnproto }}
      targetPort: capnproto
      protocol: TCP
      name: capnproto
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.receive.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: receive
{{- end }}
