apiVersion: v1
kind: Service
metadata:
  name: {{ include "deepflow.fullname" . }}-server
  labels:
    {{- include "deepflow-server.labels" . | nindent 4 }}
{{- if .Values.server.service.annotations }}
  annotations:
{{ toYaml .Values.server.service.annotations | indent 4 }}
{{- end }}
spec:
{{- if .Values.server.service.clusterIP }}
  clusterIP: {{ .Values.server.service.clusterIP }}
{{- end }}
{{- if .Values.server.service.externalIPs }}
  externalIPs:
{{ toYaml .Values.server.service.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.server.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.server.service.loadBalancerIP }}
{{- end }}
{{- if .Values.server.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{- range $cidr := .Values.server.service.loadBalancerSourceRanges }}
    - {{ $cidr }}
  {{- end }}
{{- end }}
{{- if ne .Values.server.service.type "ClusterIP" }}
  externalTrafficPolicy: {{ .Values.server.service.externalTrafficPolicy }}
{{- end }}
  ports:
  {{- $serviceType := .Values.server.service.type -}}
  {{- range .Values.server.service.ports }}
  - name: {{ tpl .name $ }}
    port: {{ tpl (toString .port) $ }}
    targetPort: {{ tpl (toString .targetPort) $ }}
    {{- if and (eq $serviceType "NodePort") (.nodePort) }}
    nodePort: {{ tpl (toString .nodePort) $ }}
    {{- end }}
    protocol: {{ tpl .protocol $ }}
  {{- end }}
{{- if .Values.server.service.additionalPorts }}
{{ toYaml .Values.server.service.additionalPorts | indent 2 }}
{{- end }}
  selector:
    {{- include "deepflow-server.selectorLabels" . | nindent 4 }}
  type: "{{ .Values.server.service.type }}"
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "deepflow.fullname" . }}-app
  labels:
    {{- include "deepflow-app.labels" . | nindent 4 }}
{{- if .Values.app.service.annotations }}
  annotations:
{{ toYaml .Values.app.service.annotations | indent 4 }}
{{- end }}
spec:
{{- if .Values.app.service.clusterIP }}
  clusterIP: {{ .Values.app.service.clusterIP }}
{{- end }}
{{- if .Values.app.service.externalIPs }}
  externalIPs:
{{ toYaml .Values.app.service.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.app.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.app.service.loadBalancerIP }}
{{- end }}
{{- if .Values.app.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{- range $cidr := .Values.app.service.loadBalancerSourceRanges }}
    - {{ $cidr }}
  {{- end }}
{{- end }}
{{- if ne .Values.app.service.type "ClusterIP" }}
  externalTrafficPolicy: {{ .Values.app.service.externalTrafficPolicy }}
{{- end }}
  ports:
  {{- $serviceType := .Values.app.service.type -}}
  {{- range .Values.app.service.ports }}
  - name: {{ tpl .name $ }}
    port: {{ tpl (toString .port) $ }}
    targetPort: {{ tpl (toString .targetPort) $ }}
    {{- if and (eq $serviceType "NodePort") (.nodePort) }}
    nodePort: {{ tpl (toString .nodePort) $ }}
    {{- end }}
    protocol: {{ tpl .protocol $ }}
  {{- end }}
{{- if .Values.app.service.additionalPorts }}
{{ toYaml .Values.app.service.additionalPorts | indent 2 }}
{{- end }}
  selector:
    {{- include "deepflow-app.selectorLabels" . | nindent 4 }}
  type: "{{ .Values.app.service.type }}"