apiVersion: v1
kind: Service
metadata:
  name: {{ template "pomerium.databroker.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ template "pomerium.databroker.name" . }}
    helm.sh/chart: {{ template "pomerium.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/component: databroker
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | indent 4 }}
{{- end }}
{{- if or .Values.databroker.service.annotations .Values.service.annotations }}
  annotations:
  {{- if .Values.databroker.service.annotations }}
  {{- range $key, $value := .Values.databroker.service.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  {{- else if .Values.service.annotations }}
  {{- range $key, $value := .Values.service.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  {{- end }}
{{- end }}
spec:
{{- if .Values.databroker.service.clusterIP }}
  clusterIP: {{ .Values.databroker.service.clusterIP }}
{{- end }}
  type: {{ .Values.databroker.service.type }}
  ports:
    - port: {{ template "pomerium.service.externalPort" . }}
      targetPort: {{ template "pomerium.grpcTrafficPort.name" . }}
      protocol: TCP
      name: {{ template "pomerium.grpcTrafficPort.name" . }}
    - name: metrics
      port: {{ .Values.metrics.port }}
      protocol: TCP
      targetPort: metrics
{{- if hasKey .Values.service "nodePort" }}
    nodePort: {{ .Values.service.nodePort }}
{{- end }}
  selector:
    app.kubernetes.io/name: {{ template "pomerium.databroker.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
