{{- if .Values.ingest.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "elasticsearch.ingest.fullname" . }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: ingest
  annotations: {{ include "common.tplvalues.render" ( dict "value" .Values.ingest.service.annotations "context" $) | nindent 4 }}
spec:
  type: {{ .Values.ingest.service.type | quote }}
  {{- if and (eq .Values.ingest.service.type "LoadBalancer") (not (empty .Values.ingest.service.loadBalancerIP)) }}
  loadBalancerIP: {{ .Values.ingest.service.loadBalancerIP }}
  {{- end }}
  publishNotReadyAddresses: true
  ports:
    - name: {{ include "elasticsearch.httpPortName" . }}
      port: 9200
      targetPort: {{ include "elasticsearch.httpPortName" . }}
    - name: tcp-transport
      port: {{ .Values.ingest.service.port }}
      targetPort: transport
      {{- if and (or (eq .Values.ingest.service.type "NodePort") (eq .Values.ingest.service.type "LoadBalancer")) (not (empty .Values.ingest.service.nodePort)) }}
      nodePort: {{ .Values.ingest.service.nodePort }}
      {{- else if eq .Values.ingest.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: ingest
{{- end }}
