{{- if .Values.dataplatform.emitter.enabled }}
apiVersion: v1
kind: Service
metadata:
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: dataplatform-emitter
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.dataplatform.emitter.service.labels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.dataplatform.emitter.service.labels "context" $ ) | nindent 4 }}
    {{- end }}
  name: "{{ include "dataplatform.emitter-name" . }}"
  {{- if or .Values.dataplatform.emitter.service.annotations .Values.commonAnnotations }}
  annotations:
    {{- if .Values.dataplatform.emitter.service.annotations }}
    {{ include "common.tplvalues.render" ( dict "value" .Values.dataplatform.emitter.service.annotations "context" $) | nindent 4 }}
    {{- end }}
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
  {{- end }}
  namespace: {{ .Release.Namespace | quote }}
spec:
  type: {{ .Values.dataplatform.emitter.service.type }}
  {{ if eq .Values.dataplatform.emitter.service.type "LoadBalancer" }}
  loadBalancerSourceRanges: {{ .Values.dataplatform.emitter.service.loadBalancerSourceRanges }}
  {{ end }}
  {{- if (and (eq .Values.dataplatform.emitter.service.type "LoadBalancer") (not (empty .Values.dataplatform.emitter.service.loadBalancerIP))) }}
  loadBalancerIP: {{ .Values.dataplatform.emitter.service.loadBalancerIP }}
  {{- end }}
  ports:
    - name: tcp-client
      port: {{ .Values.dataplatform.emitter.service.ports.http }}
      protocol: TCP
      targetPort: emitter-port
      {{- if and (or (eq .Values.dataplatform.emitter.service.type "NodePort") (eq .Values.dataplatform.emitter.service.type "LoadBalancer")) (not (empty .Values.dataplatform.emitter.service.nodePorts.http)) }}
      nodePort: {{ .Values.dataplatform.emitter.service.nodePorts.http }}
      {{- else if eq .Values.dataplatform.emitter.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: dataplatform-emitter
{{ end }}
