From e54e3a824e4cb55d148ae8615fd5b0bcaf8a6bf7 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 10 Aug 2023 09:48:04 +0800 Subject: [PATCH] Adjust minio new sequence, now it will check whether bucket exist first and then create one if it doesn't exist --- modules/storage/minio.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/storage/minio.go b/modules/storage/minio.go index e2ce09d07a51..791edae89e23 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -89,12 +89,16 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage, return nil, convertMinioErr(err) } - if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{ - Region: config.Location, - }); err != nil { - // Check to see if we already own this bucket (which happens if you run this twice) - exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket) - if !exists || errBucketExists != nil { + // Check to see if we already own this bucket + exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket) + if errBucketExists != nil { + return nil, convertMinioErr(err) + } + + if !exists { + if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{ + Region: config.Location, + }); err != nil { return nil, convertMinioErr(err) } }