{{- if .Values.prometheus.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "metallb.fullname" . }}-controller
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "metallb.chart" . }}
    app: {{ template "metallb.name" . }}
    component: controller
spec:
  jobLabel: jobLabel
  selector:
    matchLabels:
      app: {{ template "metallb.name" . }}
      release: {{ .Release.Name | quote }}
      component: controller
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  endpoints:
  - port: metrics
    {{- if .Values.prometheus.serviceMonitor.interval }}
    interval: {{ .Values.prometheus.serviceMonitor.interval }}
    {{- end }}
{{- if .Values.prometheus.serviceMonitor.metricRelabelings }}
    metricRelabelings:
{{ toYaml .Values.prometheus.serviceMonitor.metricRelabelings | indent 4 }}
{{- end }}
{{- if .Values.prometheus.serviceMonitor.relabelings }}
    relabelings:
{{ toYaml .Values.prometheus.serviceMonitor.relabelings | indent 4 }}
{{- end }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "metallb.fullname" . }}-speaker
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "metallb.chart" . }}
    app: {{ template "metallb.name" . }}
    component: speaker
spec:
  jobLabel: jobLabel
  selector:
    matchLabels:
      app: {{ template "metallb.name" . }}
      release: {{ .Release.Name | quote }}
      component: speaker
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  endpoints:
  - port: metrics
    {{- if .Values.prometheus.serviceMonitor.interval }}
    interval: {{ .Values.prometheus.serviceMonitor.interval }}
    {{- end }}
{{- if .Values.prometheus.serviceMonitor.metricRelabelings }}
    metricRelabelings:
{{ toYaml .Values.prometheus.serviceMonitor.metricRelabelings | indent 4 }}
{{- end }}
{{- if .Values.prometheus.serviceMonitor.relabelings }}
    relabelings:
{{ toYaml .Values.prometheus.serviceMonitor.relabelings | indent 4 }}
{{- end }}
{{- end }}
