apiVersion: v1
kind: Service
metadata:
{{- if .Values.service.discovery.annotations }}
  annotations:
{{ tpl (toYaml .Values.discovery.annotations) . | indent 4 }}
{{- else if and (.Values.service.annotations) (not .Values.service.discovery.separateAnnotations) }}
  annotations:
{{ tpl (toYaml .Values.service.annotations) . | indent 4 }}
{{- end }}
  name: {{ printf "%s-discovery" (include "rabbitmq-ha.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ template "rabbitmq-ha.name" . }}
    chart: {{ template "rabbitmq-ha.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  clusterIP: None
  ports:
    - name: http
      protocol: TCP
      port: {{ .Values.rabbitmqManagerPort }}
      targetPort: http
    - name: amqp
      protocol: TCP
      port: {{ .Values.rabbitmqNodePort }}
      targetPort: amqp
    - name: epmd
      protocol: TCP
      port: {{ .Values.rabbitmqEpmdPort }}
      targetPort: epmd
    {{- if .Values.rabbitmqSTOMPPlugin.enabled }}
    - name: stomp-tcp
      protocol: TCP
      port: 61613
      targetPort: stomp-tcp
    - name: stomp-ssl
      protocol: TCP
      port: 61614
      targetPort: stomp-ssl
    {{- end }}
    {{- if .Values.rabbitmqWebSTOMPPlugin.enabled }}
    - name: stomp-ws
      protocol: TCP
      port: 15674
      targetPort: stomp-ws
    {{- end }}
    {{- if .Values.rabbitmqMQTTPlugin.enabled }}
    - name: mqtt-tcp
      protocol: TCP
      port: 1883
      targetPort: mqtt-tcp
    - name: mqtt-ssl
      protocol: TCP
      port: 8883
      targetPort: mqtt-ssl
    {{- end }}
    {{- if .Values.rabbitmqWebMQTTPlugin.enabled }}
    - name: mqtt-ws
      protocol: TCP
      port: 15675
      targetPort: mqtt-ws
    {{- end }}
    {{- if .Values.rabbitmqAmqpsSupport.enabled }}
    - name: amqps
      protocol: TCP
      port: {{ .Values.rabbitmqAmqpsSupport.amqpsNodePort }}
      targetPort: amqps
    {{- end }}
  publishNotReadyAddresses: true
  selector:
    app: {{ template "rabbitmq-ha.name" . }}
    release: {{ .Release.Name }}
  type: ClusterIP
