apiVersion: v1
kind: Service
metadata:
{{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
  name: {{ template "rabbitmq-ha.fullname" . }}
  labels:
    app: {{ template "rabbitmq-ha.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels | indent 4 }}
{{- end }}
spec:
  clusterIP: "{{ .Values.service.clusterIP }}"
{{- if .Values.service.externalIPs }}
  externalIPs:
{{ toYaml .Values.service.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: "{{ .Values.service.loadBalancerIP }}"
{{- end }}
{{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.service.loadBalancerSourceRanges | indent 4 }}
{{- end }}
  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 }}
    {{ if .Values.prometheus.exporter.enabled }}
    - name: exporter
      protocol: TCP
      port: {{ .Values.prometheus.exporter.port }}
      targetPort: exporter
    {{ end }}
  selector:
    app: {{ template "rabbitmq-ha.name" . }}
    release: {{ .Release.Name }}
  type: {{ .Values.service.type }}
