apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: pzoo
  namespace: jolt
spec:
  selector:
    matchLabels:
      app: zookeeper
      storage: persistent
      appalias: pzoo
  serviceName: "pzoo"
  replicas: 3
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: zookeeper
        storage: persistent
        appalias: pzoo
      annotations:
        ad.datadoghq.com/zookeeper.check_names: '["zk"]'
        ad.datadoghq.com/zookeeper.init_configs: '[{}]'
        ad.datadoghq.com/zookeeper.logs: |
          [
            {
              "source": "zookeeper",
              "service": "pzoo"
            }
          ]
        ad.datadoghq.com/zookeeper.instances: |
          [
            {
              "host": "%%host%%",
              "port": 2181
            }
          ]
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: appalias
                operator: In
                values:
                - pzoo
            topologyKey: "kubernetes.io/hostname"
      terminationGracePeriodSeconds: 10
      initContainers:
      - name: init-config
        image: solsson/kafka-initutils@sha256:f6d9850c6c3ad5ecc35e717308fddb47daffbde18eb93e98e031128fe8b899ef
        command: ['/bin/bash', '/etc/kafka-configmap/init.sh']
        volumeMounts:
        - name: configmap
          mountPath: /etc/kafka-configmap
        - name: config
          mountPath: /etc/kafka
        - name: data
          mountPath: /var/lib/zookeeper
      containers:
      - name: zookeeper
        image: solsson/kafka:2.4.1@sha256:79761e15919b4fe9857ec00313c9df799918ad0340b684c0163ab7035907bb5a
        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: 50m
            memory: 500Mi
          limits:
            cpu: 100m
            memory: 1Gi
        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: data
          mountPath: /var/lib/zookeeper
      volumes:
      - name: configmap
        configMap:
          name: zookeeper-config
      - name: config
        emptyDir: {}
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: aws-efs
      resources:
        requests:
          storage: 8Gi
