From b2e9b4ef0cd0ca557a4962f8a8b0d519cf6f3793 Mon Sep 17 00:00:00 2001 From: carlchen Date: Fri, 13 Dec 2024 11:23:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20project-manager=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AEmongodb=E5=89=AF=E6=9C=AC=E9=9B=86=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../etc/bcs-project-manager.yaml | 1 + bcs-services/bcs-project-manager/go.mod | 2 +- .../internal/config/config.go | 1 + .../internal/provider/manager/register.go | 1 + .../internal/store/init.go | 1 + .../script/migrations/itsm/migrate.go | 1 + .../script/migrations/project/migrate.go | 25 +++++++++++-------- .../script/migrations/variable/migrate.go | 10 +++++--- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/bcs-services/bcs-project-manager/etc/bcs-project-manager.yaml b/bcs-services/bcs-project-manager/etc/bcs-project-manager.yaml index 794187f0ec..fe23dbdacc 100644 --- a/bcs-services/bcs-project-manager/etc/bcs-project-manager.yaml +++ b/bcs-services/bcs-project-manager/etc/bcs-project-manager.yaml @@ -17,6 +17,7 @@ etcd: ca: "" mongo: address: "127.0.0.1:27017" + replicaset: "" connecttimeout: 5 database: "bcsproject_project" username: "admin" diff --git a/bcs-services/bcs-project-manager/go.mod b/bcs-services/bcs-project-manager/go.mod index 7977914b8a..93dbf28da2 100644 --- a/bcs-services/bcs-project-manager/go.mod +++ b/bcs-services/bcs-project-manager/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - github.com/Tencent/bk-bcs/bcs-common v0.0.0-20240803071244-414878b26fa9 + github.com/Tencent/bk-bcs/bcs-common v0.0.0-20241212023042-2c0651f4eded github.com/Tencent/bk-bcs/bcs-common/common/task v0.0.0-20240619071101-df2f4bc5060b github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20240418123107-72b120390195 github.com/TencentBlueKing/iam-go-sdk v0.1.6 diff --git a/bcs-services/bcs-project-manager/internal/config/config.go b/bcs-services/bcs-project-manager/internal/config/config.go index 2a7ac4b6bd..857d9c5169 100644 --- a/bcs-services/bcs-project-manager/internal/config/config.go +++ b/bcs-services/bcs-project-manager/internal/config/config.go @@ -34,6 +34,7 @@ type EtcdConfig struct { // MongoConfig mongo db config type MongoConfig struct { Address string `yaml:"address"` + Replicaset string `yaml:"replicaset"` ConnectTimeout uint `yaml:"connecttimeout"` Database string `yaml:"database"` Username string `yaml:"username"` diff --git a/bcs-services/bcs-project-manager/internal/provider/manager/register.go b/bcs-services/bcs-project-manager/internal/provider/manager/register.go index 27442bb604..84ef31d15d 100644 --- a/bcs-services/bcs-project-manager/internal/provider/manager/register.go +++ b/bcs-services/bcs-project-manager/internal/provider/manager/register.go @@ -56,6 +56,7 @@ func RunTaskManager() (*task.TaskManager, error) { }, Backend: &bcsmongo.Options{ Hosts: strings.Split(config.GlobalConf.Mongo.Address, ","), + Replicaset: config.GlobalConf.Mongo.Replicaset, ConnectTimeoutSeconds: int(config.GlobalConf.Mongo.ConnectTimeout), Database: config.GlobalConf.Mongo.Database, Username: config.GlobalConf.Mongo.Username, diff --git a/bcs-services/bcs-project-manager/internal/store/init.go b/bcs-services/bcs-project-manager/internal/store/init.go index 47649ee123..0e3a8c982d 100644 --- a/bcs-services/bcs-project-manager/internal/store/init.go +++ b/bcs-services/bcs-project-manager/internal/store/init.go @@ -53,6 +53,7 @@ func NewMongo(conf *config.MongoConfig) *mongo.DB { mongoOptions := &mongo.Options{ Hosts: strings.Split(conf.Address, ","), + Replicaset: conf.Replicaset, ConnectTimeoutSeconds: int(conf.ConnectTimeout), Database: conf.Database, Username: conf.Username, diff --git a/bcs-services/bcs-project-manager/script/migrations/itsm/migrate.go b/bcs-services/bcs-project-manager/script/migrations/itsm/migrate.go index a463db4614..7833380888 100644 --- a/bcs-services/bcs-project-manager/script/migrations/itsm/migrate.go +++ b/bcs-services/bcs-project-manager/script/migrations/itsm/migrate.go @@ -57,6 +57,7 @@ func initDB() error { // mongo store.InitMongo(&config.MongoConfig{ Address: config.GlobalConf.Mongo.Address, + Replicaset: config.GlobalConf.Mongo.Replicaset, ConnectTimeout: config.GlobalConf.Mongo.ConnectTimeout, Database: config.GlobalConf.Mongo.Database, Username: config.GlobalConf.Mongo.Username, diff --git a/bcs-services/bcs-project-manager/script/migrations/project/migrate.go b/bcs-services/bcs-project-manager/script/migrations/project/migrate.go index af7e93c335..fbdfe0bdbb 100644 --- a/bcs-services/bcs-project-manager/script/migrations/project/migrate.go +++ b/bcs-services/bcs-project-manager/script/migrations/project/migrate.go @@ -45,17 +45,18 @@ const ( ) var ( - mysqlHost string - mysqlPort uint - mysqlUser string - mysqlPwd string - mysqlDBName string - mongoAddr string - mongoUser string - mongoPwd string - mongoDBName string - initProject bool - migrateCC bool + mysqlHost string + mysqlPort uint + mysqlUser string + mysqlPwd string + mysqlDBName string + mongoAddr string + mongoReplicaset string + mongoUser string + mongoPwd string + mongoDBName string + initProject bool + migrateCC bool ccdb *gorm.DB model store.ProjectModel @@ -122,6 +123,7 @@ func parseFlags() { // mongo flag.StringVar(&mongoAddr, "mongo_addr", "", "mongo address") + flag.StringVar(&mongoReplicaset, "mongo_replicaset", "", "mongo replicaset") flag.StringVar(&mongoUser, "mongo_user", "", "access mongo username") flag.StringVar(&mongoPwd, "mongo_pwd", "", "access mongo password") flag.StringVar(&mongoDBName, "mongo_db_name", "", "access mongo db name") @@ -138,6 +140,7 @@ func initDB() error { // mongo store.InitMongo(&config.MongoConfig{ Address: mongoAddr, + Replicaset: mongoReplicaset, ConnectTimeout: 5, Database: mongoDBName, Username: mongoUser, diff --git a/bcs-services/bcs-project-manager/script/migrations/variable/migrate.go b/bcs-services/bcs-project-manager/script/migrations/variable/migrate.go index 6200e51686..71bd2d0fcd 100644 --- a/bcs-services/bcs-project-manager/script/migrations/variable/migrate.go +++ b/bcs-services/bcs-project-manager/script/migrations/variable/migrate.go @@ -60,10 +60,11 @@ var ( ccDBName string // bcs mongodb config - mongoAddr string - mongoUser string - mongoPwd string - mongoDBName string + mongoAddr string + mongoReplicaset string + mongoUser string + mongoPwd string + mongoDBName string // db instance ccDB *gorm.DB @@ -88,6 +89,7 @@ func parseFlags() { // mongo for bcs-project-manager flag.StringVar(&mongoAddr, "mongo_addr", "", "mongo address") + flag.StringVar(&mongoReplicaset, "mongo_replicaset", "", "mongo replicaset") flag.StringVar(&mongoUser, "mongo_user", "", "access mongo username") flag.StringVar(&mongoPwd, "mongo_pwd", "", "access mongo password") flag.StringVar(&mongoDBName, "mongo_db_name", "", "access mongo db name")