---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kafka-broker
  namespace: default
  labels:
    name: kafka-broker
    part-of: tno
    version: 1.0.0
    component: kafka-broker
    managed-by: kustomize
    created-by: jeremy.foster
spec:
  podManagementPolicy: OrderedReady
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      statefulset: kafka-cluster
  serviceName: kafka-headless
  updateStrategy:
    type: RollingUpdate
  volumeClaimTemplates:
    - metadata:
        name: kafka-data
        annotations:
          volume.beta.kubernetes.io/storage-class: netapp-block-standard
        labels:
          name: kafka-broker
          part-of: tno
          component: kafka-broker
      spec:
        storageClassName: netapp-block-standard
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 5Gi
  template:
    metadata:
      labels:
        name: kafka-broker
        part-of: tno
        component: kafka-broker
        statefulset: kafka-cluster
    spec:
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccountName: tno
      terminationGracePeriodSeconds: 0
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: statefulset
                    operator: In
                    values:
                      - kafka-cluster
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: kafka-broker
          image: image-registry.openshift-image-registry.svc:5000/9b301c-tools/kafka:dev
          imagePullPolicy: Always
          volumeMounts:
            - name: kafka-data
              mountPath: /var/lib/kafka/data
          ports:
            - containerPort: 9092
              protocol: TCP
            - containerPort: 29092
              protocol: TCP
            - containerPort: 29094
              protocol: TCP
            - containerPort: 9101
              protocol: TCP
          resources:
            requests:
              cpu: 50m
              memory: 1Gi
            limits:
              cpu: 100m
              memory: 2Gi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          env:
            - name: POD_IP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.podIP
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            # Set by entrypoint script, because this feature 'fieldPath' does not work.
            # - name: KAFKA_BROKER_ID
            #   valueFrom:
            #     fieldRef:
            #       apiVersion: v1
            #       fieldPath: metadata.annotations['spec.pod.beta.kubernetes.io/statefulset-index']
          envFrom:
            - configMapRef:
                name: kafka-broker
          # livenessProbe:
          #   exec:
          #     command:
          #       - bin/kafka-topics
          #       - --zookeeper
          #       - "zookeeper:2181"
          #       - --list
          #   initialDelaySeconds: 60
          #   timeoutSeconds: 5
          # readinessProbe:
          #   exec:
          #     command:
          #       - bin/kafka-topics
          #       - --zookeeper
          #       - "zookeeper:2181"
          #       - --list
          #   initialDelaySeconds: 60
          #   timeoutSeconds: 5
