apiVersion: v1
kind: Service
metadata:
  name: {{ include "mongodb-sharded.serviceName" . }}
  labels: {{ include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: mongos
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.service.annotations "context" $ ) | nindent 4 }}  
spec:
  type: {{ .Values.service.type }}
  {{- if and .Values.service.loadBalancerIP (eq .Values.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if and (eq .Values.service.type "LoadBalancer") .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{ with .Values.service.loadBalancerSourceRanges }}
{{ toYaml . | indent 4 }}
  {{- end }}
  {{- end }}
  {{- if and (eq .Values.service.type "ClusterIP") .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
  ports:
    - name: mongodb
      port: {{ .Values.service.port }}
      targetPort: mongodb
      {{- if .Values.service.nodePort }}
      nodePort: {{ .Values.service.nodePort }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.metrics.enabled }}
    - name: metrics
      port: 9216
      targetPort: metrics
    {{- end }}
    {{- if .Values.service.extraPorts }}
      {{- include "common.tplvalues.render" (dict "value" .Values.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector: {{ include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: mongos
  sessionAffinity: {{ default "None" .Values.service.sessionAffinity }}
