{{- if .Values.prometheus.monitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "prometheus-node-exporter.fullname" . }}
  namespace: {{ template "prometheus-node-exporter.namespace" . }}
  labels: {{ include "prometheus-node-exporter.labels" . | indent 4 }}
  {{- if .Values.prometheus.monitor.additionalLabels }}
{{ toYaml .Values.prometheus.monitor.additionalLabels | indent 4 }}
  {{- end }}
spec:
  selector:
    matchLabels:
      app: {{ template "prometheus-node-exporter.name" . }}
      release: {{ .Release.Name }}
  endpoints:
    - port: metrics
      scheme: {{ $.Values.prometheus.monitor.scheme }}
      {{- if $.Values.prometheus.monitor.bearerTokenFile }}
      bearerTokenFile: {{ $.Values.prometheus.monitor.bearerTokenFile }}
      {{- end }}
      {{- if $.Values.prometheus.monitor.tlsConfig }}
      tlsConfig: {{ toYaml $.Values.prometheus.monitor.tlsConfig | nindent 8 }}
      {{- end }}
      {{- if .Values.prometheus.monitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.prometheus.monitor.scrapeTimeout }}
      {{- end }}
{{- if .Values.prometheus.monitor.relabelings }}
      relabelings:
{{ toYaml .Values.prometheus.monitor.relabelings | indent 6 }}
{{- end }}
{{- end }}