# Copyright (c) 2020 SIGHUP s.r.l All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

---
apiVersion: batch/v1
kind: Job
metadata:
  name: minio-setup
  labels:
    k8s-app: minio-setup
spec:
  template:
    metadata:
      labels:
        k8s-app: minio-setup
    spec:
      serviceAccountName: wait-for-minio
      restartPolicy: OnFailure
      volumes:
      - name: config
        emptyDir: {}
      initContainers:
      - name: wait-for-minio
        image: groundnuty/k8s-wait-for:v1.2
        imagePullPolicy: Always
        args: ["pod", "$(MINIO_STS_NAME)-0"]
      containers:
      - name: mc
        image: minio/mc:latest
        imagePullPolicy: Always
        envFrom:
        - secretRef:
            name: minio-credentials
        command:
        - /bin/sh
        - -c
        - "mc --config-dir=/config config host add $(MINIO_NAMESPACE) http://$(MINIO_STS_NAME)-0.$(MINIO_SERVICE_NAME):9000 ${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY} && mc --config-dir=/config mb -p $(MINIO_NAMESPACE)/$(MINIO_NAMESPACE)"
        volumeMounts:
        - name: config
          mountPath: "/config"
