apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: zoo
  namespace: kafka
spec:
  selector:
    matchLabels:
      app: zookeeper
      storage: zookeeper-zoo
  serviceName: "zoo"
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: zookeeper
        storage: zookeeper-zoo
      annotations:
        app: zoo
    spec:
      terminationGracePeriodSeconds: 10
      initContainers:
        - name: init-config
          image: solsson/kafka-initutils:lastest@sha256:c8582b9df3b3ca9d804e2d914994411fb9b2d94353c4d5476f0a63cf75e59eb0
          command: ["/bin/bash", "/etc/kafka-configmap/init.sh"]
          env:
            - name: ID_OFFSET
              value: "4"
          volumeMounts:
            - name: configmap
              mountPath: /etc/kafka-configmap
            - name: config
              mountPath: /etc/kafka
            - name: zookeeper-zoo
              mountPath: /var/lib/zookeeper
      containers:
        - name: zookeeper
          image: solsson/kafka:2.4.0@sha256:17f35e6dc3b5687107e0dae4cc0f3fc30d6613724e7b75fc1ed4d1a6f0744965
          env:
            - name: KAFKA_LOG4J_OPTS
              value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
          command:
            - ./bin/zookeeper-server-start.sh
            - /etc/kafka/zookeeper.properties
          lifecycle:
            preStop:
              exec:
                command:
                  [
                    "sh",
                    "-ce",
                    "kill -s TERM 1; while $(kill -0 1 2>/dev/null); do sleep 1; done",
                  ]
          ports:
            - containerPort: 2181
              name: client
            - containerPort: 2888
              name: peer
            - containerPort: 3888
              name: leader-election
          resources:
            requests:
              cpu: 10m
              memory: 100Mi
            limits:
              memory: 120Mi
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - '[ "imok" = "$(echo ruok | nc -w 1 -q 1 127.0.0.1 2181)" ]'
          volumeMounts:
            - name: config
              mountPath: /etc/kafka
            - name: zookeeper-zoo
              mountPath: /var/lib/zookeeper
      volumes:
        - name: configmap
          configMap:
            name: zookeeper-config
        - name: config
          emptyDir: {}
  # volumeClaimTemplates:
  #   - metadata:
  #       name: data
  #     spec:
  #       accessModes: ["ReadWriteOnce"]
  #       resources:
  #         requests:
  #           storage: 512Mi

  volumeClaimTemplates:
    - metadata:
        name: zookeeper-zoo
        namespace: kafka
      spec:
        storageClassName: zookeeper-zoo
        accessModes:
          - ReadWriteOnce
        volumeMode: Filesystem
        resources:
          requests:
            storage: 512Mi
