{{- if or .Values.proxy.enabled (not .Values.cluster.enabled) }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "milvus.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "milvus.labels" . | indent 4 }}
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | indent 4 }}
{{- end }}
{{- if not .Values.cluster.enabled }}
    component: "standalone"
{{- else if and .Values.proxy.enabled .Values.cluster.enabled }}
    component: "proxy"
{{- end }}
{{- with .Values.service.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }}
  type: ClusterIP
  {{- if .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
{{- else if eq .Values.service.type "LoadBalancer" }}
  type: LoadBalancer
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.service.loadBalancerSourceRanges | indent 4 }}
  {{- end -}}
{{- else }}
  type: {{ .Values.service.type }}
{{- end }}
  ports:
    - name: {{ .Values.service.portName }}
      port: {{ .Values.service.port }}
      protocol: TCP
      targetPort: milvus
{{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }}
      nodePort: {{.Values.service.nodePort}}
{{- end }}
    {{- if .Values.metrics.enabled }}
    - name: metrics
      protocol: TCP
      port: 9091
      targetPort: metrics
    {{- end }}
  selector:
{{ include "milvus.matchLabels" . | indent 4 }}
{{- if not .Values.cluster.enabled }}
    component: "standalone"
{{- else if and .Values.proxy.enabled .Values.cluster.enabled }}
    component: "proxy"
{{- end }}
{{- end }}
