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

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