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

apiVersion: v1
kind: Service
metadata:
  name: {{ template "common.names.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: client
  {{- if or .Values.client.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.client.service.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.client.service.type }}
  {{- if and .Values.client.service.clusterIP (eq .Values.client.service.type "ClusterIP") }}
  clusterIP: {{ .Values.client.service.clusterIP }}
  {{- end }}
  {{- if .Values.client.service.sessionAffinity }}
  sessionAffinity: {{ .Values.client.service.sessionAffinity }}
  {{- end }}
  {{- if .Values.client.service.sessionAffinityConfig }}
  sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.client.service.sessionAffinityConfig "context" $) | nindent 4 }}
  {{- end }}
  {{- if or (eq .Values.client.service.type "LoadBalancer") (eq .Values.client.service.type "NodePort") }}
  externalTrafficPolicy: {{ .Values.client.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if and (eq .Values.client.service.type "LoadBalancer") (not (empty .Values.client.service.loadBalancerSourceRanges)) }}
  loadBalancerSourceRanges: {{ .Values.client.service.loadBalancerSourceRanges }}
  {{- end }}
  {{- if and (eq .Values.client.service.type "LoadBalancer") (not (empty .Values.client.service.loadBalancerIP)) }}
  loadBalancerIP: {{ .Values.client.service.loadBalancerIP }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.client.service.ports.http }}
      protocol: TCP
      targetPort: http
      {{- if and (or (eq .Values.client.service.type "NodePort") (eq .Values.client.service.type "LoadBalancer")) (not (empty .Values.client.service.nodePorts.http)) }}
      nodePort: {{ .Values.client.service.nodePorts.http }}
      {{- else if eq .Values.client.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.client.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.client.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.client.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: client
