apiVersion: v1
kind: Service
metadata:
  name: {{ template "kafka.fullname" . }}
  labels: {{- include "kafka.labels" . | nindent 4 }}
    app.kubernetes.io/component: kafka
  {{- if .Values.service.annotations }}
  annotations: {{- include "kafka.tplValue" (dict "value" .Values.service.annotations "context" $) | nindent 4 }}
  {{- end }}
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: tcp-client
      port: {{ .Values.service.port }}
      protocol: TCP
      targetPort: kafka-client
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }}
      nodePort: {{ .Values.service.nodePort }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "kafka.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: kafka
