{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

apiVersion: v1
kind: Service
metadata:
  name: {{ include "argo-workflows.server.fullname" . }}
  namespace: {{ .Release.Namespace | quote }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.server.image "chart" .Chart ) ) }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.commonLabels $versionLabel ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: argo-workflows
    app.kubernetes.io/component: server
  {{- if or .Values.server.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.server.service.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  {{- if and .Values.server.service.clusterIP (eq .Values.server.service.type "ClusterIP") }}
  clusterIP: {{ .Values.server.service.clusterIP }}
  {{- end }}
  type: {{ .Values.server.service.type }}
  {{- if (or (eq .Values.server.service.type "LoadBalancer") (eq .Values.server.service.type "NodePort")) }}
  externalTrafficPolicy: {{ .Values.server.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if eq .Values.server.service.type "LoadBalancer" }}
  loadBalancerSourceRanges: {{ .Values.server.service.loadBalancerSourceRanges }}
  {{- end }}
  {{- if (and (eq .Values.server.service.type "LoadBalancer") (not (empty .Values.server.service.loadBalancerIP))) }}
  loadBalancerIP: {{ .Values.server.service.loadBalancerIP }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.server.service.ports.http }}
      targetPort: web
      {{- if (and (or (eq .Values.server.service.type "NodePort") (eq .Values.server.service.type "LoadBalancer")) (not (empty .Values.server.service.nodePorts.http))) }}
      nodePort: {{ .Values.server.service.nodePorts.http }}
      {{- else if eq .Values.server.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.server.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.server.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.server.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: server
