2 set -e ; # Have script exit in the event of a failed command.
5 # Use a check-sleep-check loop to wait for Minio service to be available
8 ATTEMPTS=0 ; LIMIT=29 ; # Allow 30 attempts
9 set -e ; # fail if we can't read the keys.
10 ACCESS=$(cat /config/accesskey) ; SECRET=$(cat /config/secretkey) ;
11 set +e ; # The connections to minio are allowed to fail.
12 echo "Connecting to Minio server: $SCHEME://$MINIO_ENDPOINT:$MINIO_PORT" ;
13 MC_COMMAND="mc config host add myminio $SCHEME://$MINIO_ENDPOINT:$MINIO_PORT $ACCESS $SECRET" ;
18 ATTEMPTS=`expr $ATTEMPTS + 1` ;
19 echo \"Failed attempts: $ATTEMPTS\" ;
20 if [ $ATTEMPTS -gt $LIMIT ]; then
23 sleep 2 ; # 1 second intervals between attempts
27 set -e ; # reset `e` as active
31 # checkBucketExists ($bucket)
32 # Check if the bucket exists, by using the exit code of `mc ls`
35 CMD=$(/usr/bin/mc ls myminio/$BUCKET > /dev/null 2>&1)
39 # createBucket ($bucket, $policy, $purge)
40 # Ensure bucket exists, purging if asked to
46 # Purge the bucket, if set & exists
47 # Since PURGE is user input, check explicitly for `true`
48 if [ $PURGE = true ]; then
49 if checkBucketExists $BUCKET ; then
50 echo "Purging bucket '$BUCKET'."
51 set +e ; # don't exit if this fails
52 /usr/bin/mc rm -r --force myminio/$BUCKET
53 set -e ; # reset `e` as active
55 echo "Bucket '$BUCKET' does not exist, skipping purge."
59 # Create the bucket if it does not exist
60 if ! checkBucketExists $BUCKET ; then
61 echo "Creating bucket '$BUCKET'"
62 /usr/bin/mc mb myminio/$BUCKET
64 echo "Bucket '$BUCKET' already exists."
67 # At this point, the bucket should exist, skip checking for existence
68 # Set policy on the bucket
69 echo "Setting policy of bucket '$BUCKET' to '$POLICY'."
70 /usr/bin/mc policy $POLICY myminio/$BUCKET
73 # Try connecting to Minio instance
74 {{- if .Values.tls.enabled }}
79 connectToMinio $scheme
81 {{- if or .Values.defaultBucket.enabled }}
83 createBucket {{ .Values.defaultBucket.name }} {{ .Values.defaultBucket.policy }} {{ .Values.defaultBucket.purge }}
84 {{ else if .Values.buckets }}
86 {{- range .Values.buckets }}
87 createBucket {{ .name }} {{ .policy }} {{ .purge }}