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

{{- if and .Values.kubeProxy.enabled .Values.kubeProxy.service.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "kube-prometheus.fullname" . }}-kube-proxy
  namespace: {{ .Values.kubeProxy.namespace }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.kubeProxy.service.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: kube-proxy
  {{- 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.kubeProxy.service.ports.http }}
      protocol: TCP
      targetPort: {{ .Values.kubeProxy.service.targetPorts.http }}
  {{- if not .Values.kubeProxy.endpoints }}
  selector:
    {{- if .Values.kubeProxy.service.selector }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.kubeProxy.service.selector "context" $ ) | nindent 4 }}
    {{- else }}
    k8s-app: kube-proxy
    {{- end }}
  {{- end }}
{{- end -}}
