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

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