# helm_charts_serviceMonitor.yaml
{{- if .Values.kubeStateMetrics.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "prometheus-operator.fullname" . }}-kube-state-metrics
  namespace: {{ template "prometheus-operator.namespace" . }}
  labels:
    app: {{ template "prometheus-operator.name" . }}-kube-state-metrics
{{ include "prometheus-operator.labels" . | indent 4 }}
spec:
  jobLabel: app.kubernetes.io/name
  endpoints:
  - port: http
    {{- if .Values.kubeStateMetrics.serviceMonitor.interval }}
    interval: {{ .Values.kubeStateMetrics.serviceMonitor.interval }}
    {{- end }}
    honorLabels: true
{{- if .Values.kubeStateMetrics.serviceMonitor.metricRelabelings }}
    metricRelabelings:
{{ tpl (toYaml .Values.kubeStateMetrics.serviceMonitor.metricRelabelings | indent 4) . }}
{{- end }}
{{- if .Values.kubeStateMetrics.serviceMonitor.relabelings }}
    relabelings:
{{ toYaml .Values.kubeStateMetrics.serviceMonitor.relabelings | indent 4 }}
{{- end }}
  selector:
    matchLabels:
      app.kubernetes.io/name: kube-state-metrics
      app.kubernetes.io/instance: "{{ $.Release.Name }}"
{{- end }}