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

{{- if and .Values.thanosRuler.enabled .Values.thanosRuler.service.additionalHeadless }}
apiVersion: v1
kind: Service
metadata:
  name: {{ printf "%s-headless" (include "kube-prometheus.thanosRuler.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . }}
  {{- $versionLabel := dict "app.kubernetes.io/version" (include "common.images.version" (dict "imageRoot" .Values.thanosRuler.image "chart" .Chart)) }}
  {{- $labels := include "common.tplvalues.merge" (dict "values" (list .Values.commonLabels $versionLabel) "context" .) }}
  labels: {{ include "common.labels.standard" (dict "customLabels" $labels "context" .) | nindent 4 }}
    app.kubernetes.io/component: thanos-ruler
  {{- if or .Values.thanosRuler.service.headless.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.thanosRuler.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.thanosRuler.service.ports.http }}
      targetPort: http
      protocol: TCP
      name: http
    - port: {{ .Values.thanosRuler.service.ports.grpc }}
      targetPort: grpc
      protocol: TCP
      name: grpc
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.thanosRuler.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{ include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: thanos-ruler
{{- end }}
