apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
  name: {{ .Release.Name }}
  labels:
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  kafka:
    replicas: {{ .Values.kafka.replicas }}
    {{- if .Values.kafka.resources }}
    resources: {{- include "cozy-lib.resources.sanitize" (list .Values.kafka.resources $) | nindent 6 }}
    {{- else if ne .Values.kafka.resourcesPreset "none" }}
    resources: {{- include "cozy-lib.resources.preset" (list .Values.kafka.resourcesPreset $) | nindent 6 }}
    {{- end }}
    listeners:
      - name: plain
        port: 9092
        type: internal
        tls: false
      - name: tls
        port: 9093
        type: internal
        tls: true
      - name: external
        port: 9094
        {{- if .Values.external }}
        type: loadbalancer
        {{- else }}
        type: internal
        {{- end }}
        tls: false
    config:
      {{- if eq (int .Values.kafka.replicas) 1 }}
      offsets.topic.replication.factor: 1
      transaction.state.log.replication.factor: 1
      transaction.state.log.min.isr: 1
      default.replication.factor: 1
      min.insync.replicas: 1
      {{- else if eq (int .Values.kafka.replicas) 2 }}
      offsets.topic.replication.factor: 2
      transaction.state.log.replication.factor: 2
      transaction.state.log.min.isr: 2
      default.replication.factor: 2
      min.insync.replicas: 2
      {{- else }}
      offsets.topic.replication.factor: 3
      transaction.state.log.replication.factor: 3
      transaction.state.log.min.isr: 2
      default.replication.factor: 3
      min.insync.replicas: 2
      {{- end }}
    storage:
      type: jbod
      volumes:
      - id: 0
        type: persistent-claim
        {{- with .Values.kafka.size }}
        size: {{ . }}
        {{- end }}
        {{- with .Values.kafka.storageClass }}
        class: {{ . }}
        {{- end }}
        deleteClaim: true
    metricsConfig:
      type: jmxPrometheusExporter
      valueFrom:
        configMapKeyRef:
          name: {{ .Release.Name }}-metrics
          key: kafka-metrics-config.yml
  zookeeper:
    replicas: {{ .Values.zookeeper.replicas }}
    {{- if .Values.zookeeper.resources }}
    resources: {{- include "cozy-lib.resources.sanitize" (list .Values.zookeeper.resources $) | nindent 6 }}
    {{- else if ne .Values.zookeeper.resourcesPreset "none" }}
    resources: {{- include "cozy-lib.resources.preset" (list .Values.zookeeper.resourcesPreset $) | nindent 6 }}
    {{- end }}
    storage:
      type: persistent-claim
      {{- with .Values.zookeeper.size }}
      size: {{ . }}
      {{- end }}
      {{- with .Values.kafka.storageClass }}
      class: {{ . }}
      {{- end }}
      deleteClaim: false
    metricsConfig:
      type: jmxPrometheusExporter
      valueFrom:
        configMapKeyRef:
          name: {{ .Release.Name }}-metrics
          key: kafka-metrics-config.yml
  entityOperator:
    topicOperator: {}
    userOperator: {}
    template:
      pod:
        metadata:
         labels:
           policy.cozystack.io/allow-to-apiserver: "true"
      spec:
        enableServiceLinks: false
