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

{{- if .Values.overridesExporter.enabled }}
apiVersion: v1
kind: Service
metadata:
  name:  {{ template "grafana-mimir.overrides-exporter.fullname" . }}-headless
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: grafana-mimir
    app.kubernetes.io/component: overrides-exporter
  {{- if or .Values.commonAnnotations .Values.overridesExporter.service.headless.annotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.overridesExporter.service.headless.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  publishNotReadyAddresses: true
  type: ClusterIP
  clusterIP: None
  ports:
    - name: http
      port: {{ .Values.overridesExporter.service.ports.http }}
      targetPort: http
      protocol: TCP
      {{- if and (or (eq .Values.overridesExporter.service.type "NodePort") (eq .Values.overridesExporter.service.type "LoadBalancer")) (not (empty .Values.overridesExporter.service.nodePorts.http)) }}
      nodePort: {{ .Values.overridesExporter.service.nodePorts.http }}
      {{- else if eq .Values.overridesExporter.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    - name: grpc
      port: {{ .Values.overridesExporter.service.ports.grpc }}
      targetPort: grpc
      protocol: TCP
      {{- if and (or (eq .Values.overridesExporter.service.type "NodePort") (eq .Values.overridesExporter.service.type "LoadBalancer")) (not (empty .Values.overridesExporter.service.nodePorts.grpc)) }}
      nodePort: {{ .Values.overridesExporter.service.nodePorts.grpc }}
      {{- else if eq .Values.overridesExporter.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.overridesExporter.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.overridesExporter.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.overridesExporter.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: grafana-mimir
    app.kubernetes.io/component: overrides-exporter
{{- end }}
