apiVersion: v1
kind: Service
metadata:
  name: {{ printf "%s-%s" (include "common.names.fullname" .) (default "headless" .Values.servicenameOverride) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if or .Values.service.annotationsHeadless .Values.commonAnnotations }}
  annotations:
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
    {{- end -}}
    {{- if .Values.service.annotationsHeadless }}
    {{- include "common.tplvalues.render" (dict "value" .Values.service.annotationsHeadless "context" $) | nindent 4 }}
    {{- end -}}
  {{- end }}
spec:
  clusterIP: None
  ports:
    - name: {{ .Values.service.portNames.epmd }}
      port: {{ .Values.service.ports.epmd }}
      targetPort: epmd
    {{- if or (.Values.service.portEnabled) (not .Values.auth.tls.enabled) }}
    - name: {{ .Values.service.portNames.amqp }}
      port: {{ .Values.service.ports.amqp }}
      targetPort: amqp
    {{- end }}
    {{- if .Values.auth.tls.enabled }}
    - name: {{ .Values.service.portNames.amqpTls }}
      port: {{ .Values.service.ports.amqpTls }}
      targetPort: amqp-tls
    {{- end }}
    - name: {{ .Values.service.portNames.dist }}
      port: {{ .Values.service.ports.dist }}
      targetPort: dist
    {{- if .Values.service.managerPortEnabled }}
    - name: {{ .Values.service.portNames.manager }}
      port: {{ .Values.service.ports.manager  }}
      targetPort: stats
    {{- end }}
  selector: {{ include "common.labels.matchLabels" . | nindent 4 }}
  publishNotReadyAddresses: true
