mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 13:42:10 +08:00
fix: ensure s3 client init for s3 storage driver (#24319)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -15,12 +15,16 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/log"
|
||||
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/pending_delete"
|
||||
)
|
||||
|
||||
type SImageOptions struct {
|
||||
common_options.HostCommonOptions
|
||||
common_options.HostCommonOptions `"s3_bucket_name->default":"onecloud-images" "s3_bucket_lifecycle_keep_day->default":"0"`
|
||||
|
||||
common_options.DBOptions
|
||||
|
||||
@@ -81,5 +85,22 @@ func OnOptionsChange(oldO, newO interface{}) bool {
|
||||
}
|
||||
|
||||
func (opt SImageOptions) HasValidS3Options() bool {
|
||||
return len(opt.S3Endpoint) > 0 && len(opt.S3AccessKey) > 0 && len(opt.S3SecretKey) > 0 && len(opt.S3BucketName) > 0
|
||||
msg := []string{}
|
||||
if len(opt.S3Endpoint) <= 0 {
|
||||
msg = append(msg, "s3_endpoint is required")
|
||||
}
|
||||
if len(opt.S3AccessKey) <= 0 {
|
||||
msg = append(msg, "s3_access_key is required")
|
||||
}
|
||||
if len(opt.S3SecretKey) <= 0 {
|
||||
msg = append(msg, "s3_secret_key is required")
|
||||
}
|
||||
if len(opt.S3BucketName) <= 0 {
|
||||
msg = append(msg, "s3_bucket_name is required")
|
||||
}
|
||||
if len(msg) > 0 {
|
||||
log.Errorf("invalid s3 options: %s", strings.Join(msg, ", "))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -147,6 +147,11 @@ func StartService() {
|
||||
|
||||
if options.Options.HasValidS3Options() {
|
||||
initS3()
|
||||
log.Infof("init s3 client success")
|
||||
} else if options.Options.StorageDriver == api.IMAGE_STORAGE_DRIVER_S3 {
|
||||
log.Fatalf("storage driver is s3, but s3 options are not valid")
|
||||
} else {
|
||||
log.Infof("storage driver is not s3 and no valid s3 options, skip init s3 client")
|
||||
}
|
||||
// check image after s3 mounted
|
||||
models.CheckImages(app.GetContext())
|
||||
@@ -215,10 +220,9 @@ func initS3() {
|
||||
if err != nil {
|
||||
log.Fatalf("failed init s3 client %s", err)
|
||||
}
|
||||
if options.Options.S3BucketName == "onecloud-screendump" {
|
||||
if err = s3.SetBucketLifecycle(""); err != nil {
|
||||
log.Warningf("remove onecloud-screendump lifecycle %s", err)
|
||||
}
|
||||
// clear glance bucket lifecycle definiton
|
||||
if err = s3.SetBucketLifecycle(""); err != nil {
|
||||
log.Warningf("remove onecloud-screendump lifecycle %s", err)
|
||||
}
|
||||
|
||||
func() {
|
||||
|
||||
Reference in New Issue
Block a user