apiVersion: v1
kind: Service
metadata:
  name: {{ include "kafka.fullname" . }}
  labels:
    app: {{ include "kafka.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  ports:
  - name: broker
    port: 9092
    targetPort: kafka
{{- if and .Values.prometheus.jmx.enabled .Values.prometheus.operator.enabled }}
  - name: jmx-exporter
    protocol: TCP
    port: {{ .Values.jmx.port }}
    targetPort: prometheus
{{- end }}
  selector:
    app: {{ include "kafka.name" . }}
    release: {{ .Release.Name }}
---
{{- if and .Values.prometheus.kafka.enabled .Values.prometheus.operator.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "kafka.fullname" . }}-exporter
  labels:
    app: {{ include "kafka.name" . }}-exporter
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  ports:
  - name: kafka-exporter
    protocol: TCP
    port: {{ .Values.prometheus.kafka.port }}
    targetPort: {{ .Values.prometheus.kafka.port }}
  selector:
    app: {{ include "kafka.name" . }}-exporter
    release: {{ .Release.Name }}
{{- end }}
