apiVersion: v1
kind: Service
metadata:
  name: {{ include "dashboard.serviceName" . }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
  {{- if .Values.commonLabels }}
  {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  {{- end }}
  {{- if or .Values.dashboard.service.annotations .Values.commonAnnotations}}
  annotations:
  {{- if .Values.dashboard.service.annotations }}
  {{- include "common.tplvalues.render" (dict "value" .Values.dashboard.service.annotations "context" $) | nindent 4 }}
  {{- end }}
  {{- if .Values.commonAnnotations }}
  {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
  {{- end }}
  {{- end }}
spec:
  type: {{ .Values.dashboard.service.type }}
  {{- if (or (eq .Values.dashboard.service.type "LoadBalancer") (eq .Values.dashboard.service.type "NodePort")) }}
  externalTrafficPolicy: {{ .Values.dashboard.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if (and (eq .Values.dashboard.service.type "LoadBalancer") (not (empty .Values.dashboard.service.loadBalancerIP))) }}
  loadBalancerIP: {{ .Values.dashboard.service.loadBalancerIP }}
  {{- end }}
  {{- if (and (eq .Values.dashboard.service.type "LoadBalancer") .Values.dashboard.service.loadBalancerSourceRanges) }}
  loadBalancerSourceRanges:
  {{ toYaml .Values.dashboard.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.dashboard.service.port }}
      targetPort: dashboard-http
      {{- if (and (or (eq .Values.dashboard.service.type "NodePort") (eq .Values.dashboard.service.type "LoadBalancer")) (not (empty .Values.dashboard.service.nodePorts.http))) }}
      nodePort: {{ .Values.dashboard.service.nodePorts.http }}
      {{- else if eq .Values.dashboard.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.dashboard.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.dashboard.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
