From c25e1b59817020a3f9670e2576e464f721480942 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 3 Mar 2025 20:15:29 +0800 Subject: [PATCH] fix: glance always init s3 client (#22129) Co-authored-by: Qiu Jian --- pkg/image/options/options.go | 4 ++++ pkg/image/service/service.go | 16 +++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/image/options/options.go b/pkg/image/options/options.go index e1a308dcd3..4a185ebb8f 100644 --- a/pkg/image/options/options.go +++ b/pkg/image/options/options.go @@ -80,3 +80,7 @@ func OnOptionsChange(oldO, newO interface{}) bool { return changed } + +func (opt SImageOptions) HasValidS3Options() bool { + return len(opt.S3Endpoint) > 0 && len(opt.S3AccessKey) > 0 && len(opt.S3SecretKey) > 0 && len(opt.S3BucketName) > 0 +} diff --git a/pkg/image/service/service.go b/pkg/image/service/service.go index 5f548908a6..8ed467375a 100644 --- a/pkg/image/service/service.go +++ b/pkg/image/service/service.go @@ -139,12 +139,13 @@ func StartService() { deployclient.Init(options.Options.DeployServerSocketPath) } - if options.Options.StorageDriver == api.IMAGE_STORAGE_DRIVER_S3 { - go initS3() - } else { - // Check the images after everything is ready - go models.CheckImages() - } + go func() { + if options.Options.HasValidS3Options() { + initS3() + } + // check image after s3 mounted + models.CheckImages() + }() if !opts.IsSlaveNode { cachesync.StartTenantCacheSync(opts.TenantCacheExpireSeconds) @@ -253,7 +254,4 @@ func initS3() { break } } - - // check image after s3 mounted - models.CheckImages() }