apiVersion: v1
kind: Service
metadata:
  # This service is meant to be used by clients of the database. It exposes a ClusterIP that will
  # automatically load balance connections to the different database pods.
  name: "{{ printf "%s-%s" .Release.Name .Values.Name | trunc 56 }}-public"
  annotations:
{{ toYaml .Values.Service.annotations | indent 4 }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
{{- if .Values.Service.labels }}
{{ toYaml .Values.Service.labels | indent 4 }}
{{- end }}
spec:
  type: {{ .Values.Service.type }}
  ports:
  # The main port, served by gRPC, serves Postgres-flavor SQL, internode
  # traffic and the cli.
  - port: {{ .Values.ExternalGrpcPort }}
    targetPort: {{ .Values.InternalGrpcPort }}
    name: {{ .Values.ExternalGrpcName }}
  # The secondary port serves the UI as well as health and debug endpoints.
  - port: {{ .Values.ExternalHttpPort }}
    targetPort: {{ .Values.InternalHttpPort }}
    name: {{ .Values.HttpName }}
    {{- if ne .Values.InternalGrpcPort .Values.ExternalGrpcPort }}
  - port: {{ .Values.InternalGrpcPort }}
    targetPort: {{ .Values.InternalGrpcPort }}
    name: {{ .Values.InternalGrpcName }}
    {{- end }}
  selector:
    component: "{{ .Release.Name }}-{{ .Values.Component }}"