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

{{- if and .Values.prometheus.enabled .Values.prometheus.thanos.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "kube-prometheus.thanos.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "kube-prometheus.prometheus.labels" . | nindent 4 }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  jobLabel: {{ .Values.prometheus.thanos.serviceMonitor.jobLabel }}
  selector:
    matchLabels: {{- include "kube-prometheus.prometheus.matchLabels" . | nindent 6 }}
      app.kubernetes.io/subcomponent: thanos
  namespaceSelector:
    matchNames:
      - {{ include "common.names.namespace" . | quote }}
  endpoints:
    - port: http
      {{- if .Values.prometheus.thanos.serviceMonitor.interval }}
      interval: {{ .Values.prometheus.thanos.serviceMonitor.interval }}
      {{- end }}
      path: {{ .Values.prometheus.thanos.serviceMonitor.path }}
      {{- if .Values.prometheus.thanos.serviceMonitor.metricRelabelings }}
      metricRelabelings: {{- include "common.tplvalues.render" ( dict "value" .Values.prometheus.thanos.serviceMonitor.metricRelabelings "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.prometheus.thanos.serviceMonitor.relabelings }}
      relabelings: {{- toYaml .Values.prometheus.thanos.serviceMonitor.relabelings | nindent 8 }}
      {{- end }}
{{- end }}
