{{- if and .Values.server.enabled .Values.server.statefulSet.enabled -}}
apiVersion: v1
kind: Service
metadata:
  namespace: {{ .Release.Namespace }}
{{- if .Values.server.statefulSet.service.annotations }}
  annotations:
{{ toYaml .Values.server.statefulSet.service.annotations | indent 4}}
{{- end }}
  labels:
  {{- include "victoria-metrics.server.labels" . | nindent 4 }}
{{- if .Values.server.statefulSet.service.labels }}
{{ toYaml .Values.server.statefulSet.service.labels | indent 4}}
{{- end }}
  name: {{ template "victoria-metrics.server.fullname" . }}
spec:
  clusterIP: None
  {{- with .Values.server.statefulSet.service.healthCheckNodePort }}
  healthCheckNodePort: {{ . }}
  {{- end }}
  {{- with .Values.server.statefulSet.service.externalTrafficPolicy }}
  externalTrafficPolicy: {{ . }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.server.statefulSet.service.servicePort }}
      protocol: TCP
      targetPort: http
{{- if .Values.server.extraArgs.graphiteListenAddr }}
    - name: graphite-tcp
      protocol: TCP
      port: {{ include "split-host-port" .Values.server.extraArgs.graphiteListenAddr }}
      targetPort: graphite-tcp
{{- end }}
{{- if .Values.server.extraArgs.graphiteListenAddr }}
    - name: graphite-udp
      protocol: UDP
      port: {{ include "split-host-port" .Values.server.extraArgs.graphiteListenAddr }}
      targetPort: graphite-udp
{{- end }}
{{- if .Values.server.extraArgs.influxListenAddr }}
    - name: influx-tcp
      protocol: TCP
      port: {{ include "split-host-port" .Values.server.extraArgs.influxListenAddr }}
      targetPort: influx-tcp
{{- end }}
{{- if .Values.server.extraArgs.influxListenAddr }}
    - name: influx-udp
      protocol: UDP
      port: {{ include "split-host-port" .Values.server.extraArgs.influxListenAddr }}
      targetPort: influx-udp
{{- end }}
{{- if .Values.server.extraArgs.opentsdbHTTPListenAddr }}
    - name: opentsdbhttp
      port: {{ include "split-host-port" .Values.server.extraArgs.opentsdbHTTPListenAddr }}
      targetPort: opentsdbhttp
{{- end }}
{{- if .Values.server.extraArgs.opentsdbListenAddr }}
    - name: opentsdb-udp
      protocol: UDP
      port: {{ include "split-host-port" .Values.server.extraArgs.opentsdbListenAddr }}
      targetPort: opentsdb-udp
{{- end }}
{{- if .Values.server.extraArgs.opentsdbListenAddr }}
    - name: opentsdb-tcp
      protocol: TCP
      port: {{ include "split-host-port" .Values.server.extraArgs.opentsdbListenAddr }}
      targetPort: opentsdb-tcp
{{- end }}
  selector:
    {{- include "victoria-metrics.server.matchLabels" . | nindent 4 }}
{{- end -}}
