{{- if .Values.prometheus.monitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "coredns.fullname" . }}
  {{- if .Values.prometheus.monitor.namespace }}
  namespace: {{ .Values.prometheus.monitor.namespace }}
  {{- end }}
  labels:
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    {{- if .Values.isClusterService }}
    k8s-app: {{ .Chart.Name | quote }}
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "CoreDNS"
    {{- end }}
    app.kubernetes.io/name: {{ template "coredns.name" . }}
    {{- if .Values.prometheus.monitor.additionalLabels }}
{{ toYaml .Values.prometheus.monitor.additionalLabels | indent 4 }}
    {{- end }}
spec:
  selector:
    matchLabels:
      app.kubernetes.io/instance: {{ .Release.Name | quote }}
      {{- if .Values.isClusterService }}
      k8s-app: {{ .Chart.Name | quote }}
      {{- end }}
      app.kubernetes.io/name: {{ template "coredns.name" . }}
      app.kubernetes.io/component: metrics
  endpoints:
    - port: metrics
{{- end }}
