{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "goldpinger.fullname" . }}
  {{- if .Values.serviceMonitor.namespace }}
  namespace: {{ .Values.serviceMonitor.namespace }}
  {{- end }}
  labels:
    {{- include "goldpinger.labels" . | nindent 4 }}
    {{- range $key, $value := .Values.serviceMonitor.selector }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  endpoints:
    - port: http
      interval: {{ .Values.serviceMonitor.interval }}
      {{- if .Values.serviceMonitor.honorLabels }}
      honorLabels: true
      {{- end }}
      {{- with .Values.serviceMonitor.metricRelabelings }}
      metricRelabelings:
        {{- toYaml . | nindent 8 }}
      {{- end }}
  jobLabel: name
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  selector:
    matchLabels:
      {{- include "goldpinger.selectorLabels" . | nindent 6 }}
{{- end -}}
