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

apiVersion: v1
kind: Service
metadata:
  name: {{ printf "%s-hubble-peers" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: cilium
    app.kubernetes.io/component: hubble-peers
  {{- if or .Values.hubble.peers.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" (dict "values" (list .Values.hubble.peers.service.annotations .Values.commonAnnotations) "context" .) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  # There's no reason to support LoadBalancer nor NodePort (and their associated customizations)
  # given Hubble Peer service is only used for Hubble Relay to connect to Hubble Peer servers internally.
  type: ClusterIP
  {{- if .Values.hubble.peers.service.clusterIP }}
  clusterIP: {{ .Values.hubble.peers.service.clusterIP }}
  {{- end }}
  internalTrafficPolicy: {{ .Values.hubble.peers.service.internalTrafficPolicy }}
  ports:
    - name: tcp-hubble-peer
      port: {{ .Values.hubble.peers.service.port }}
      targetPort: hubble-peer
      protocol: TCP
    {{- if .Values.hubble.peers.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.hubble.peers.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" (dict "values" (list .Values.agent.podLabels .Values.commonLabels) "context" .) | fromYaml }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: cilium
    app.kubernetes.io/component: agent
