{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "stackdriver-exporter.name" .  }}
  {{- if .Values.serviceMonitor.namespace }}
  namespace: {{ .Values.serviceMonitor.namespace }}
  {{- end }}
  labels:
    chart: {{ template "stackdriver-exporter.chart" . }}
    app: {{ template "stackdriver-exporter.name" . }}
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
    {{- if .Values.serviceMonitor.additionalLabels }}
{{ toYaml .Values.serviceMonitor.additionalLabels | indent 4 }}
    {{- end }}
spec:
  endpoints:
  - port: http
    {{- if .Values.serviceMonitor.interval }}
    interval: {{ .Values.serviceMonitor.interval }}
    {{- end }}
    honorLabels: {{ .Values.serviceMonitor.honorLabels }}
  selector:
    matchLabels:
      chart: {{ template "stackdriver-exporter.chart" . }}
      app: {{ template "stackdriver-exporter.name" . }}
      release: "{{ .Release.Name }}"
      heritage: "{{ .Release.Service }}"
{{- end }}
