# Copyright 2023 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: platform.confluent.io/v1beta1
kind: Kafka
metadata:
  name: my-cluster
spec:
  replicas: 3
  tls:
    autoGeneratedCerts: true
  image:
    application: confluentinc/cp-server:7.4.0
    init: confluentinc/confluent-init-container:2.6.0
  dataVolumeCapacity: 100Gi
  storageClass:
    name: premium-rwo
  configOverrides:
    server:
      - 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
      - auto.create.topics.enable=true
  listeners:
    custom:
    - name: sasl
      port: 9094
      authentication:
        type: plain
        jaasConfig:
          secretRef: my-user-credentials
      tls:
        enabled: true
  podTemplate:
    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: my-cluster
          clusterId: kafka
          platform.confluent.io/type: kafka
    envVars:
    - name: KAFKA_HEAP_OPTS
      value: "-Xmx4G -Xms4G"
    resources:
      requests:
        memory: 5Gi
        cpu: "1"
      limits:
        memory: 5Gi
        cpu: "2"
    probe:
      readiness:
        failureThreshold: 15
  dependencies:
    zookeeper:
      endpoint: zookeeper.kafka.svc.cluster.local:2182
      tls:
        enabled: true
---
apiVersion: platform.confluent.io/v1beta1
kind: Zookeeper
metadata:
  name: zookeeper
spec:
  replicas: 3
  tls:
    autoGeneratedCerts: true
  image:
    application: confluentinc/cp-zookeeper:7.4.0
    init: confluentinc/confluent-init-container:2.6.0
  dataVolumeCapacity: 90Gi
  logVolumeCapacity: 10Gi
  storageClass:
    name: premium-rwo
  podTemplate:
    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: zookeeper
          clusterId: kafka
          platform.confluent.io/type: zookeeper
    resources:
      requests:
        memory: 3Gi
        cpu: "1"
      limits:
        memory: 3Gi
        cpu: "2"

