# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
  name: "${name}"
  namespace: "${namespace}"
spec:
  kafka:
    version: "${kafka_config.version}"
    replicas: ${kafka_config.replicas}
    template:
      pod:
        tolerations:
        - key: "app.stateful/component"
          operator: "Equal"
          value: "kafka-broker"
          effect: NoSchedule
        affinity:
          nodeAffinity:
            preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              preference:
                matchExpressions:
                - key: "app.stateful/component"
                  operator: In
                  values:
                  - "kafka-broker"
        topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: "topology.kubernetes.io/zone"
          whenUnsatisfiable: DoNotSchedule
          labelSelector:
            matchLabels:
              app.kubernetes.io/name: kafka
              strimzi.io/cluster:  "${name}"
              strimzi.io/component-type: kafka
    resources:
      requests:
        memory: 5Gi
        cpu: "1"
      limits:
        memory: 5Gi
        cpu: "2"
    jvmOptions:
      -Xms: ${kafka_config.jvm_memory}
      -Xmx: ${kafka_config.jvm_memory}
    listeners:
      - name: plain
        port: 9092
        type: internal
        tls: false
      - name: tls
        port: 9093
        type: internal
        tls: true
    config:
      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
      inter.broker.protocol.version: "3.4"
    storage:
      type: jbod
      volumes:
      - id: 0
        type: persistent-claim
        size: ${kafka_config.volume_claim_size}
        class: premium-rwo
        deleteClaim: false
  zookeeper:
    template:
      pod:
        affinity:
          nodeAffinity:
            preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              preference:
                matchExpressions:
                - key: "app.stateful/component"
                  operator: In
                  values:
                  - "zookeeper"
        topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: "topology.kubernetes.io/zone"
          whenUnsatisfiable: DoNotSchedule
          labelSelector:
            matchLabels:
              app.kubernetes.io/name: zookeeper
              strimzi.io/cluster:  "${name}"
              strimzi.io/component-type: zookeeper
    replicas: ${zookeeper_config.replicas}
    resources:
      requests:
        memory: 2560Mi
        cpu: 1000m
      limits:
        memory: 2560Mi
        cpu: 2000m
    jvmOptions:
      -Xms: ${zookeeper_config.jvm_memory}
      -Xmx: ${zookeeper_config.jvm_memory}
    storage:
      type: persistent-claim
      size: ${zookeeper_config.volume_claim_size}
      class: premium-rwo
      deleteClaim: false
  entityOperator:
    tlsSidecar:
      resources:
        requests:
          cpu: 100m
          memory: 128Mi
        limits:
          cpu: 500m
          memory: 128Mi
    topicOperator:
      resources:
        requests:
          cpu: 100m
          memory: 512Mi
        limits:
          cpu: 500m
          memory: 512Mi
    userOperator:
      resources:
        requests:
          cpu: 500m
          ephemeral-storage: 1Gi
          memory: 2Gi
        limits:
          cpu: 500m
          ephemeral-storage: 1Gi
          memory: 2Gi
