# Source: cp-helm-charts/charts/cp-zookeeper/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: cp-helm-charts-cp-zookeeper
  labels:
    app: cp-zookeeper
    chart: cp-zookeeper-0.1.0
    release: cp-helm-charts
    heritage: Helm
    gitops.jenkins-x.io/pipeline: 'namespaces'
  annotations:
    meta.helm.sh/release-name: 'cp-helm-charts'
  namespace: kafka
spec:
  selector:
    matchLabels:
      app: cp-zookeeper
      release: cp-helm-charts
  serviceName: cp-helm-charts-cp-zookeeper-headless
  podManagementPolicy: OrderedReady
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: cp-zookeeper
        release: cp-helm-charts
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "5556"
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: "app"
                      operator: In
                      values:
                        - cp-zookeeper
                    - key: "release"
                      operator: In
                      values:
                        - cp-helm-charts
                topologyKey: "kubernetes.io/hostname"
      containers:
        - name: prometheus-jmx-exporter
          image: "solsson/kafka-prometheus-jmx-exporter@sha256:6f82e2b0464f50da8104acd7363fb9b995001ddff77d248379f8788e78946143"
          imagePullPolicy: "IfNotPresent"
          command:
            - java
            - -XX:+UnlockExperimentalVMOptions
            - -XX:+UseCGroupMemoryLimitForHeap
            - -XX:MaxRAMFraction=1
            - -XshowSettings:vm
            - -jar
            - jmx_prometheus_httpserver.jar
            - "5556"
            - /etc/jmx-zookeeper/jmx-zookeeper-prometheus.yml
          ports:
            - containerPort: 5556
          resources: {}
          volumeMounts:
            - name: jmx-config
              mountPath: /etc/jmx-zookeeper
        - name: cp-zookeeper-server
          image: "confluentinc/cp-zookeeper:6.0.1"
          imagePullPolicy: "IfNotPresent"
          securityContext:
            runAsUser: 0
          ports:
            - containerPort: 2181
              name: client
            - containerPort: 2888
              name: server
            - containerPort: 3888
              name: leader-election
            - containerPort: 5555
              name: jmx
          resources: {}
          env:
            - name: KAFKA_HEAP_OPTS
              value: "-Xms128M -Xmx128M"
            - name: KAFKA_JMX_PORT
              value: "5555"
            - name: ZOOKEEPER_TICK_TIME
              value: "2000"
            - name: ZOOKEEPER_SYNC_LIMIT
              value: "5"
            - name: ZOOKEEPER_INIT_LIMIT
              value: "10"
            - name: ZOOKEEPER_MAX_CLIENT_CNXNS
              value: "60"
            - name: ZOOKEEPER_AUTOPURGE_SNAP_RETAIN_COUNT
              value: "3"
            - name: ZOOKEEPER_AUTOPURGE_PURGE_INTERVAL
              value: "24"
            - name: ZOOKEEPER_CLIENT_PORT
              value: "2181"
            - name: ZOOKEEPER_SERVERS
              value: "cp-helm-charts-cp-zookeeper-0.cp-helm-charts-cp-zookeeper-headless.kafka:2888:3888"
            # ZOOKEEPER_SERVER_ID is required just to pass cp-zookeeper ensure script for env check,
            # the value(metadata.mame) is not used and will be overwritten in command part
            - name: ZOOKEEPER_SERVER_ID
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          command:
            - "bash"
            - "-c"
            - |
              ZK_FIX_HOST_REGEX="s/${HOSTNAME}\.[^:]*:/0.0.0.0:/g"
              ZOOKEEPER_SERVER_ID=$((${HOSTNAME##*-}+1)) \
              ZOOKEEPER_SERVERS=`echo $ZOOKEEPER_SERVERS | sed -e "$ZK_FIX_HOST_REGEX"` \
              /etc/confluent/docker/run
          volumeMounts:
            - name: datadir
              mountPath: /var/lib/zookeeper/data
            - name: datalogdir
              mountPath: /var/lib/zookeeper/log
      volumes:
        - name: datadir
          emptyDir: {}
        - name: datalogdir
          emptyDir: {}
        - name: jmx-config
          configMap:
            name: cp-helm-charts-cp-zookeeper-jmx-configmap
