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

apiVersion: v1
kind: Service
metadata:
  name: {{ template "grafana-tempo.querier.fullname" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: querier
  {{- if or .Values.commonAnnotations .Values.querier.service.annotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.querier.service.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.querier.service.type }}
  {{- if .Values.querier.service.sessionAffinity }}
  sessionAffinity: {{ .Values.querier.service.sessionAffinity }}
  {{- end }}
  {{- if .Values.querier.service.sessionAffinityConfig }}
  sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.querier.service.sessionAffinityConfig "context" $) | nindent 4 }}
  {{- end }}
  {{- if and .Values.querier.service.clusterIP (eq .Values.querier.service.type "ClusterIP") }}
  clusterIP: {{ .Values.querier.service.clusterIP }}
  {{- end }}
  {{- if or (eq .Values.querier.service.type "LoadBalancer") (eq .Values.querier.service.type "NodePort") }}
  externalTrafficPolicy: {{ .Values.querier.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if and (eq .Values.querier.service.type "LoadBalancer") (not (empty .Values.querier.service.loadBalancerSourceRanges)) }}
  loadBalancerSourceRanges: {{ .Values.querier.service.loadBalancerSourceRanges }}
  {{- end }}
  {{- if and (eq .Values.querier.service.type "LoadBalancer") (not (empty .Values.querier.service.loadBalancerIP)) }}
  loadBalancerIP: {{ .Values.querier.service.loadBalancerIP }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.querier.service.ports.http }}
      targetPort: http
      protocol: TCP
      {{- if (and (or (eq .Values.querier.service.type "NodePort") (eq .Values.querier.service.type "LoadBalancer")) (not (empty .Values.querier.service.nodePorts.http))) }}
      nodePort: {{ .Values.querier.service.nodePorts.http }}
      {{- else if eq .Values.querier.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    - name: grpc
      port: {{ .Values.querier.service.ports.grpc }}
      targetPort: grpc
      protocol: TCP
      {{- if (and (or (eq .Values.querier.service.type "NodePort") (eq .Values.querier.service.type "LoadBalancer")) (not (empty .Values.querier.service.nodePorts.grpc))) }}
      nodePort: {{ .Values.querier.service.nodePorts.grpc }}
      {{- else if eq .Values.querier.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.querier.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.querier.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.querier.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: querier
