apiVersion: v1
kind: Service
metadata:
  name: {{ include "kuiper.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kuiper.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  {{- if eq .Values.service.type "LoadBalancer" }}
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  {{- end }}
  ports:
  - name: restapi
    port:  {{ .Values.service.restapi | default 9081 }}
    protocol: TCP
    targetPort:  restapi
    {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.restapi)) }}
    nodePort: {{ .Values.service.nodePorts.restapi }}
    {{- else if eq .Values.service.type "ClusterIP" }}
    nodePort: null
    {{- end }}
  - name: kuiper
    port: {{ .Values.service.kuiper | default 20498 }}
    protocol: TCP
    targetPort: kuiper
    {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.kuiper)) }}
    nodePort: {{ .Values.service.nodePorts.kuiper }}
    {{- else if eq .Values.service.type "ClusterIP" }}
    nodePort: null
    {{- end }}
  selector:
    {{- include "kuiper.selectorLabels" . | nindent 4 }}

---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "kuiper.fullname" . }}-headless
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kuiper.labels" . | nindent 4 }}
spec:
  type: ClusterIP
  sessionAffinity: None
  clusterIP: None
  selector:
    {{- include "kuiper.selectorLabels" . | nindent 4 }}