{{- if .Values.metrics.jmx.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "kafka.fullname" . }}-jmx-metrics
  labels: {{- include "kafka.labels" . | nindent 4 }}
    app.kubernetes.io/component: kafka
  {{- if .Values.metrics.jmx.service.annotations }}
  annotations: {{ include "kafka.tplValue" ( dict "value" .Values.metrics.jmx.service.annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.metrics.jmx.service.type }}
  {{- if eq .Values.metrics.jmx.service.type "LoadBalancer" }}
  {{- if .Values.metrics.jmx.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.metrics.jmx.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.metrics.jmx.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{- toYaml .Values.metrics.jmx.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  {{- end }}
  {{- if and (eq .Values.metrics.jmx.service.type "ClusterIP") .Values.metrics.jmx.service.clusterIP }}
  clusterIP: {{ .Values.metrics.jmx.service.clusterIP }}
  {{- end }}
  ports:
    - name: http-metrics
      port: {{ .Values.metrics.jmx.service.port }}
      protocol: TCP
      targetPort: metrics
      {{- if and (or (eq .Values.metrics.jmx.service.type "NodePort") (eq .Values.metrics.jmx.service.type "LoadBalancer")) (not (empty .Values.metrics.jmx.service.nodePort)) }}
      nodePort: {{ .Values.metrics.jmx.service.nodePort }}
      {{- else if eq .Values.metrics.jmx.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "kafka.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: kafka
{{- end }}
