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

apiVersion: v1
kind: Service
metadata:
  name: {{ printf "%s-headless" (include "kafka.controller.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.service.headless.controller.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: controller-eligible
    app.kubernetes.io/part-of: kafka
  {{- if or .Values.service.headless.controller.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.service.headless.controller.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  publishNotReadyAddresses: true
  ports:
    {{- if not .Values.controller.controllerOnly }}
    - name: tcp-interbroker
      port: {{ .Values.service.ports.interbroker }}
      protocol: TCP
      targetPort: interbroker
    - name: tcp-client
      port: {{ .Values.service.ports.client }}
      protocol: TCP
      targetPort: client
    {{- end }}
    - name: tcp-controller
      protocol: TCP
      port: {{ .Values.service.ports.controller }}
      targetPort: controller
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.controller.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: controller-eligible
    app.kubernetes.io/part-of: kafka
  {{- with .Values.service.headless.ipFamilyPolicy }}
  ipFamilyPolicy: {{ . | quote }}
  {{- end }}
  {{- with .Values.service.headless.ipFamilies }}
  ipFamilies:
  {{- . | toYaml | nindent 2 }}
  {{- end }}
