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

{{- if and .Values.prometheus.enabled .Values.prometheus.configReloader.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "kube-prometheus.configReloader.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.configReloader.serviceMonitor.jobLabel }}
  selector:
    matchLabels: {{- include "kube-prometheus.prometheus.matchLabels" . | nindent 6 }}
      app.kubernetes.io/subcomponent: config-reloader
  namespaceSelector:
    matchNames:
      - {{ include "common.names.namespace" . | quote }}
  endpoints:
    - port: http
      {{- if .Values.prometheus.configReloader.serviceMonitor.interval }}
      interval: {{ .Values.prometheus.configReloader.serviceMonitor.interval }}
      {{- end }}
      path: {{ .Values.prometheus.configReloader.serviceMonitor.path }}
      {{- if .Values.prometheus.configReloader.serviceMonitor.metricRelabelings }}
      metricRelabelings: {{- include "common.tplvalues.render" ( dict "value" .Values.prometheus.configReloader.serviceMonitor.metricRelabelings "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.prometheus.configReloader.serviceMonitor.relabelings }}
      relabelings: {{- toYaml .Values.prometheus.configReloader.serviceMonitor.relabelings | nindent 8 }}
      {{- end }}
{{- end }}
