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

{{- if and .Values.compactor.enabled (not .Values.compactor.cronJob.enabled) }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "thanos.compactor.fullname" . }}
  namespace: {{ include "common.names.namespace" . }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.compactor.service.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: compactor
    {{- include "thanos.servicemonitor.matchLabels" . | nindent 4 -}}
  {{- if or .Values.compactor.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.compactor.service.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.compactor.service.type }}
  {{- if and .Values.compactor.service.clusterIP (eq .Values.compactor.service.type "ClusterIP") }}
  clusterIP: {{ .Values.compactor.service.clusterIP }}
  {{- end }}
  {{- if ne .Values.compactor.service.type "ClusterIP" }}
  externalTrafficPolicy: {{ .Values.compactor.service.externalTrafficPolicy }}
  {{- end }}
  {{- if and .Values.compactor.service.loadBalancerIP (eq .Values.compactor.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.compactor.service.loadBalancerIP }}
  {{- end }}
  {{- if and (eq .Values.compactor.service.type "LoadBalancer") .Values.compactor.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.compactor.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  {{- if .Values.compactor.service.ipFamilyPolicy }}
  ipFamilyPolicy: {{ .Values.compactor.service.ipFamilyPolicy }}
  {{- end }}
  {{- if .Values.compactor.service.ipFamilies }}
  ipFamilies: {{ toYaml .Values.compactor.service.ipFamilies | nindent 4 }}
  {{- end }}
  ports:
    - port: {{ .Values.compactor.service.ports.http }}
      targetPort: http
      protocol: TCP
      name: http
      {{- if and (or (eq .Values.compactor.service.type "NodePort") (eq .Values.compactor.service.type "LoadBalancer")) .Values.compactor.service.nodePorts.http }}
      nodePort: {{ .Values.compactor.service.nodePorts.http }}
      {{- else if eq .Values.compactor.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.compactor.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.compactor.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector:
    {{- if .Values.compactor.service.labelSelectorsOverride }}
    {{- include "common.tplvalues.render" (dict "value" .Values.compactor.service.labelSelectorsOverride "context" $) | nindent 4 }}
    {{- else }}
    {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.compactor.podLabels .Values.commonLabels ) "context" . ) }}
    {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: compactor
    {{- end }}
{{- end }}
