apiVersion: v1
kind: Service
metadata:
  name: {{ include "scdf.fullname" . }}-server
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: server
  {{- if .Values.server.service.annotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.server.service.annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.server.service.type }}
  {{- if and .Values.server.service.clusterIP (eq .Values.server.service.type "ClusterIP") }}
  clusterIP: {{ .Values.server.service.clusterIP }}
  {{- end }}
  {{- if and .Values.server.service.loadBalancerIP (eq .Values.server.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.server.service.loadBalancerIP }}
  {{- end }}
  {{- if and (eq .Values.server.service.type "LoadBalancer") .Values.server.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.server.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  {{- if or (eq .Values.server.service.type "LoadBalancer") (eq .Values.server.service.type "NodePort") }}
  externalTrafficPolicy: {{ .Values.server.service.externalTrafficPolicy | quote }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.server.service.port }}
      targetPort: http
      {{- if (and (or (eq .Values.server.service.type "NodePort") (eq .Values.server.service.type "LoadBalancer")) (not (empty .Values.server.service.nodePort))) }}
      nodePort: {{ .Values.server.service.nodePort }}
      {{- else if eq .Values.server.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{ include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: server
