apiVersion: v1
kind: Service
metadata:
  name: {{ template "zookeeper.fullname" . }}-headless
  namespace: {{ .Release.Namespace }}
  labels: {{- include "zookeeper.labels" . | nindent 4 }}
    app.kubernetes.io/component: zookeeper
    {{- if .Values.commonLabels }}
    {{- include "zookeeper.tplValue" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if or .Values.commonAnnotations .Values.service.annotations }}
  annotations:
    {{- if .Values.service.headless.annotations }}
    {{- include "zookeeper.tplValue" ( dict "value" .Values.service.headless.annotations "context" $ ) | nindent 4 }}\
    {{- end }}
    {{- if .Values.commonAnnotations }}
    {{- include "zookeeper.tplValue" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
  {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  publishNotReadyAddresses: {{ .Values.service.publishNotReadyAddresses }}
  ports:
    {{ if not .Values.service.tls.disable_base_client_port }}
    - name: tcp-client
      port: 2181
      targetPort: client
    {{ end }}
    {{ if .Values.service.tls.client_enable }}
    - name: tcp-client-tls
      port: {{ .Values.service.tls.client_port }}
      targetPort: client-tls
    {{ end }}
    - name: follower
      port: 2888
      targetPort: follower
    - name: tcp-election
      port: 3888
      targetPort: election
  selector: {{- include "zookeeper.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: zookeeper
