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

{{- if and .Values.kubeControllerManager.enabled .Values.kubeControllerManager.service.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "kube-prometheus.fullname" . }}-kube-controller-manager
  namespace: {{ .Values.kubeControllerManager.namespace }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.kubeControllerManager.service.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: kube-controller-manager
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - name: http-metrics
      port: {{ .Values.kubeControllerManager.service.ports.http }}
      protocol: TCP
      targetPort: {{ .Values.kubeControllerManager.service.targetPorts.http }}
  {{- if not .Values.kubeControllerManager.endpoints }}
  selector:
    {{- if .Values.kubeControllerManager.service.selector }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.kubeControllerManager.service.selector "context" $ ) | nindent 4 }}
    {{- else }}
    component: kube-controller-manager
    {{- end }}
{{- end }}
{{- end }}
