apiVersion: v1
kind: Service
metadata:
{{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
  labels:
    {{- include "centrifugo.labels" . | nindent 4 }}
  name: {{ include "centrifugo.fullname" . }}
  namespace: {{ .Release.Namespace }}
spec:
  type: "{{ .Values.service.type }}"
{{- if .Values.service.clusterIP }}
  clusterIP: "{{ .Values.service.clusterIP }}"
{{- end }}
{{- 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
      port: {{ .Values.service.port }}
      protocol: TCP
      targetPort: http
      {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }}
      nodePort: {{ .Values.service.nodePort }}
      {{- end }}
      {{- if .Values.grpc.enabled }}
    - name: grpc
      port: {{ .Values.service.grpcPort }}
      protocol: TCP
      targetPort: grpc
      {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.grpcNodePort))) }}
      nodePort: {{ .Values.service.grpcNodePort }}
      {{- end }}
      {{- end }}
  selector:
    {{- include "centrifugo.selectorLabels" . | nindent 4 }}
