{{- if and .Values.serviceMonitor.enabled (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "prometheus-nats-exporter.fullname" . }}
  {{- with .Values.serviceMonitor.namespace }}
  namespace: {{ . }}
  {{- end }}
  labels:
    app.kubernetes.io/name: {{ include "prometheus-nats-exporter.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "prometheus-nats-exporter.chart" . }}
    {{- with .Values.serviceMonitor.additionalLabels }}
{{ toYaml . | indent 4 }}
    {{- end }}
spec:
  endpoints:
    - port: http
      honorLabels: true
      {{- with .Values.serviceMonitor.interval }}
      interval: {{ . }}
      {{- end }}
      {{- with .Values.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ . }}
      {{- end }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "prometheus-nats-exporter.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

