apiVersion: v1
kind: Service
metadata:
  name: {{ template "dex.fullname" . }}
  labels:
{{ include "dex.labels" . | indent 4 }}
{{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
spec:
  type: {{ .Values.service.type}}
  sessionAffinity: None
  ports:
  - name: {{ if .Values.https }}https{{ else }}http{{ end }}
    targetPort: {{ if .Values.https }}https{{ else }}http{{ end }}
{{- if eq "NodePort" .Values.service.type }}
    nodePort: {{ .Values.ports.web.nodePort }}
{{- end }}
    port: {{ .Values.ports.web.servicePort }}
{{- if .Values.grpc }}
  - name: grpc
    targetPort: grpc
  {{- if eq "NodePort" .Values.service.type }}
    nodePort: {{ .Values.ports.grpc.nodePort }}
  {{- end }}
    port: {{ .Values.ports.grpc.servicePort }}
{{- end }}
{{- if .Values.telemetry }}
  - name: telemetry
    targetPort: telemetry
  {{- if eq "NodePort" .Values.service.type }}
    nodePort: {{ .Values.ports.telemetry.nodePort }}
  {{- end }}
    port: {{ .Values.ports.telemetry.servicePort }}
{{- end }}
{{- if hasKey .Values.service "externalIPs" }}
  externalIPs:
{{ toYaml .Values.service.externalIPs | indent 4 }}
{{- end }}
{{- if hasKey .Values.service "loadBalancerIP" }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{- end }}
  selector:
    app.kubernetes.io/name: {{ include "dex.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
