apiVersion: v1
kind: Service
metadata:
  name: {{ include "rabbitmq.fullname" . }}
  labels:
    {{- include "rabbitmq.labels" . | nindent 4 }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  ports:
    - port: {{ .Values.service.amqp.port }}
      targetPort: amqp
      name: amqp
      {{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.amqp.nodePort) }}
      nodePort: {{ .Values.service.amqp.nodePort }}
      {{- end }}
    {{- if .Values.options.ssl.enabled }}
    - port: {{ .Values.service.amqps.port }}
      targetPort: amqps
      name: amqps
      {{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.amqps.nodePort) }}
      nodePort: {{ .Values.service.amqps.nodePort }}
      {{- end }}
    {{- end }}
    {{- if .Values.managementPlugin.enabled }}
    - port: {{ .Values.service.mgmt.port }}
      targetPort: mgmt
      name: mgmt
      {{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.mgmt.nodePort) }}
      nodePort: {{ .Values.service.mgmt.nodePort }}
      {{- end }}
    {{- end }}
    {{- if .Values.prometheusPlugin.enabled }}
    - port: {{ .Values.service.prometheus.port }}
      targetPort: prometheus
      name: prometheus
      {{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.prometheus.nodePort) }}
      nodePort: {{ .Values.service.prometheus.nodePort }}
      {{- end }}
    {{- end }}
  {{- if and (eq .Values.service.type "LoadBalancer") (.Values.service.loadBalancerIP) }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
  selector:
    {{- include "rabbitmq.selectorLabels" . | nindent 4 }}
  type: {{ .Values.service.type }}