apiVersion: batch/v1
kind: Job
metadata:
  name: "even-driven-setup"
spec:
  template:
    spec:
      containers:
        - name: images-bucket-event-topic-creation
          image: confluentinc/cp-kafka:5.0.1
          imagePullPolicy: IfNotPresent
          command:
            - sh
            - -c
            - |
              # Create the topic if not exist
              kafka-topics --zookeeper blobstore-index-confluent-cp-zookeeper --topic images-bucket-event --create --partitions 1 --replication-factor 1 --if-not-exists
              kafka-topics --zookeeper blobstore-index-confluent-cp-zookeeper --topic thumbnails-event --create --partitions 1 --replication-factor 1 --if-not-exists
        - name: images-bucket-creation
          image: minio/mc:RELEASE.2018-12-05T22-59-07Z
          imagePullPolicy: IfNotPresent
          env:
          - name: ACCESSKEY
            valueFrom:
              secretKeyRef:
                name: blobstore-index-minio
                key: accesskey
          - name: SECRETKEY
            valueFrom:
              secretKeyRef:
                name: blobstore-index-minio
                key: secretkey
          command:
            - sh
            - -c
            - |
              # Add blobstore-index-minio to client host list
              mc config host add blobstore-index-minio http://blobstore-index-minio:9000 $ACCESSKEY $SECRETKEY S3v4
              # Create buckets: thumbnails and images
              mc mb blobstore-index-minio/thumbnails --ignore-existing
              mc mb blobstore-index-minio/images --ignore-existing
              # Add bucket event notifications to images bucket
              mc event remove blobstore-index-minio/images arn:minio:sqs:us-east-1:1:kafka
              mc event add blobstore-index-minio/images arn:minio:sqs:us-east-1:1:kafka --event put --suffix .jpg
      restartPolicy: Never
  backoffLimit: 1