{{- if .Values.serviceMonitor.enabled -}}
{{- $mergedVMServiceScrapeAnnotations := mustMerge .Values.serviceMonitor.annotations .Values.annotations -}}
{{- $mergedVMServiceScrapeLabels := mustMerge .Values.serviceMonitor.extraLabels .Values.extraLabels -}}
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMServiceScrape
metadata:
  name: {{ template "vm-operator.fullname" . }}
  namespace: {{ $.Release.Namespace }}
  labels:
{{ include "vm-operator.labels" . | indent 4 }}
{{- with $mergedVMServiceScrapeLabels }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- with $mergedVMServiceScrapeAnnotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
  selector:
    matchLabels:
      {{- include "vm-operator.selectorLabels" . | nindent 6 }}
  endpoints:
    - port: http
      {{- if .Values.serviceMonitor.scheme }}
      scheme: {{ .Values.serviceMonitor.scheme }}
      {{- end }}
      {{- if .Values.serviceMonitor.interval }}
      interval: {{ .Values.serviceMonitor.interval }}
      {{- end }}
      {{- if .Values.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
      {{- end }}
      {{- with .Values.serviceMonitor.tlsConfig }}
      tlsConfig:
          {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.serviceMonitor.relabelings }}
      relabelings:
          {{- toYaml . | nindent 8 }}
      {{- end }}
  namespaceSelector:
    matchNames:
      - {{ $.Release.Namespace }}
{{- end }}
