{{ if and (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") .Values.monitoring.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "backupRestore.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
{{- include "backupRestore.labels" . | nindent 4 }}
{{- with .Values.monitoring.serviceMonitor.additionalLabels }}
    {{- toYaml . | nindent 4 }}
{{- end }}
spec:
  selector:
    matchLabels:
{{- include "backupRestore.labels" . | nindent 6 }}
  endpoints:
  - port: http
    path: /metrics
    {{- with .Values.monitoring.serviceMonitor.metricRelabelings }}
    metricRelabelings:
      {{- toYaml . | nindent 6 }}
    {{- end }}
    {{- with .Values.monitoring.serviceMonitor.relabelings }}
    relabelings:
      {{- toYaml . | nindent 4 }}
    {{- end }}
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
{{- end }}
