{{ if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "prometheus-mongodb-exporter.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "prometheus-mongodb-exporter.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "prometheus-mongodb-exporter.chart" . }}
    {{- range $key, $value := .Values.serviceMonitor.additionalLabels }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
  {{- if .Values.serviceMonitor.namespace }}
  namespace: {{ .Values.serviceMonitor.namespace }}
  {{- end }}
spec:
  endpoints:
  - port: metrics
    interval: {{ .Values.serviceMonitor.interval }}
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "prometheus-mongodb-exporter.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

