{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.kubeScheduler.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "kube-prometheus.fullname" . }}-kube-scheduler
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.kubeScheduler.serviceMonitor.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: kube-scheduler
  {{- if or .Values.commonAnnotations .Values.kubeScheduler.serviceMonitor.annotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.kubeScheduler.serviceMonitor.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  jobLabel: {{ .Values.kubeScheduler.serviceMonitor.jobLabel }}
  selector:
    matchLabels:
      app.kubernetes.io/component: kube-scheduler
  namespaceSelector:
    matchNames:
      - {{ .Values.kubeScheduler.namespace }}
  {{- with .Values.kubeScheduler.serviceMonitor.sampleLimit }}
  sampleLimit: {{ . }}
  {{- end }}
  endpoints:
    - port: http-metrics
      bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
      {{- if .Values.kubeScheduler.serviceMonitor.https }}
      scheme: https
      tlsConfig:
        caFile: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        {{- if .Values.kubeScheduler.serviceMonitor.insecureSkipVerify }}
        insecureSkipVerify: {{ .Values.kubeScheduler.serviceMonitor.insecureSkipVerify }}
        {{- end }}
        {{- if .Values.kubeScheduler.serviceMonitor.serverName }}
        serverName: {{ .Values.kubeScheduler.serviceMonitor.serverName }}
        {{- end }}
      {{- end }}
      {{- if .Values.kubeScheduler.serviceMonitor.interval }}
      interval: {{ .Values.kubeScheduler.serviceMonitor.interval }}
      {{- end }}
      {{- if .Values.kubeScheduler.serviceMonitor.metricRelabelings }}
      metricRelabelings: {{- include "common.tplvalues.render" (dict "value" .Values.kubeScheduler.serviceMonitor.metricRelabelings "context" $) | nindent 6 }}
      {{- end }}
      {{- if .Values.kubeScheduler.serviceMonitor.relabelings }}
      relabelings: {{- include "common.tplvalues.render" (dict "value" .Values.kubeScheduler.serviceMonitor.relabelings "context" $) | nindent 6 }}
      {{- end }}
{{- end }}
