{{- if .Values.controller.prometheus.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "common.names.fullname" . }}-controller
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: controller
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  jobLabel: {{ .Values.controller.prometheus.serviceMonitor.jobLabel | quote }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: controller
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  endpoints:
  - port: metrics
    {{- if .Values.controller.prometheus.serviceMonitor.interval }}
    interval: {{ .Values.controller.prometheus.serviceMonitor.interval }}
    {{- end }}
    {{- if .Values.controller.prometheus.serviceMonitor.metricRelabelings }}
    metricRelabelings: {{ toYaml .Values.controller.prometheus.serviceMonitor.metricRelabelings | nindent 4 }}
    {{- end }}
    {{- if .Values.controller.prometheus.serviceMonitor.relabelings }}
    relabelings: {{ toYaml .Values.controller.prometheus.serviceMonitor.relabelings | nindent 4 }}
    {{- end }}
{{- end -}}
