apiVersion: batch/v1
kind: Job
metadata:
  name: provisioning-topics
  annotations:
    "helm.sh/hook": "post-install"  
spec:
  template:
    spec:
      containers:
      - name: create-topics
        image: "{{ .Values.kafkaImage }}:{{ .Values.kafkaImageTag }}"
        command: ["/bin/sh", "/opt/provisioning/create-topics.sh"]
        env:
        - name: ZOOKEEPER
          valueFrom:
            configMapKeyRef:
              name: kafka-config
              key: ZOOKEEPER
        - name: REPLICAS
          valueFrom:
            configMapKeyRef:
              name: kafka-config
              key: KAFKA_MINIMUM_REPLICAS
        volumeMounts:
        - name: kafka-create-topics
          mountPath: /opt/provisioning
      initContainers:
      - name: wait
        image: busybox
        command: ["/bin/sh", "/opt/provisioning/wait-for-minimum-kafkas.sh"]
        env:
        - name: KAFKA_BROKERS
          valueFrom:
            configMapKeyRef:
              name: kafka-config
              key: KAFKA_BROKERS
        - name: REPLICAS
          valueFrom:
            configMapKeyRef:
              name: kafka-config
              key: KAFKA_MINIMUM_REPLICAS
        volumeMounts:
        - name: provisioning-scripts
          mountPath: /opt/provisioning
      volumes:
        - name: provisioning-scripts
          configMap:
            name: provisioning-scripts
        - name: kafka-create-topics
          configMap:
            name: kafka-create-topics
        - name: kafka-config
          configMap:
            name: kafka-config
      restartPolicy: Never
  backoffLimit: 3
