{{- if .Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "vault.fullname" . }}
  labels:
    app: {{ template "vault.name" . }}
    chart: {{ template "vault.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
{{- if .Values.serviceMonitor.additionalLabels }}
{{ toYaml .Values.serviceMonitor.additionalLabels | indent 4 }}
{{- end }}
spec:
  endpoints:
  - port: "metrics"
    interval: {{ .Values.serviceMonitor.interval }}
    honorLabels: true
  jobLabel: {{ .Values.serviceMonitor.jobLabel}}
  selector:
    matchLabels:
      app: {{ template "vault.name" . }}
      release: {{ .Release.Name }}
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
{{- end -}}
