{{- if .Values.coreDns.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "kube-prometheus.fullname" . }}-coredns
  namespace: {{ .Release.Namespace }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: {{ template "kube-prometheus.fullname" . }}-coredns
spec:
  jobLabel: k8s-app
  selector:
    matchLabels:
      app.kubernetes.io/component: {{ template "kube-prometheus.fullname" . }}-coredns
  namespaceSelector:
    matchNames:
      - {{ .Values.coreDns.namespace }}
  endpoints:
  - port: http-metrics
    {{- if .Values.coreDns.serviceMonitor.interval}}
    interval: {{ .Values.coreDns.serviceMonitor.interval }}
    {{- end }}
    bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
{{- if .Values.coreDns.serviceMonitor.metricRelabelings }}
    metricRelabelings:
{{ tpl (toYaml .Values.coreDns.serviceMonitor.metricRelabelings | indent 4) . }}
{{- end }}
{{- if .Values.coreDns.serviceMonitor.relabelings }}
    relabelings:
{{ toYaml .Values.coreDns.serviceMonitor.relabelings | indent 4 }}
{{- end }}
{{- end }}
