From 2d1202b32c1a975fe6cf7b139d1ab4ed292bcca1 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Sat, 12 Aug 2023 17:00:51 +0800 Subject: [PATCH] Check first if minio bucket exists before trying to create it (#26420) (#26465) Backport #26420 by @lunny For some reason, the permission of the client_id and secret may cannot create bucket, so now we will check whether bucket does exist first and then try to create a bucket if it doesn't exist. Try to fix #25984 Co-authored-by: Lunny Xiao Co-authored-by: silverwind --- 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 e7c315ae44..f50f341022 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -90,12 +90,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) } } -- 2.39.5