Skip to content

Commit 2d1202b

Browse files
GiteaBotlunnysilverwind
authored
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 <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
1 parent 9112ce2 commit 2d1202b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

modules/storage/minio.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,16 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
9090
return nil, convertMinioErr(err)
9191
}
9292

93-
if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{
94-
Region: config.Location,
95-
}); err != nil {
96-
// Check to see if we already own this bucket (which happens if you run this twice)
97-
exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket)
98-
if !exists || errBucketExists != nil {
93+
// Check to see if we already own this bucket
94+
exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket)
95+
if errBucketExists != nil {
96+
return nil, convertMinioErr(err)
97+
}
98+
99+
if !exists {
100+
if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{
101+
Region: config.Location,
102+
}); err != nil {
99103
return nil, convertMinioErr(err)
100104
}
101105
}

0 commit comments

Comments
 (0)