From 70a440e31fefe16a203847109127284062857ade Mon Sep 17 00:00:00 2001 From: carlchen Date: Fri, 13 Dec 2024 17:51:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20cluster-resources=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 --- bcs-services/cluster-resources/cmd/init.go | 1 + bcs-services/cluster-resources/go.mod | 2 +- bcs-services/cluster-resources/pkg/common/envs/envs.go | 1 + bcs-services/cluster-resources/pkg/config/config.go | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bcs-services/cluster-resources/cmd/init.go b/bcs-services/cluster-resources/cmd/init.go index 967a4f4f05..7febedf6f1 100644 --- a/bcs-services/cluster-resources/cmd/init.go +++ b/bcs-services/cluster-resources/cmd/init.go @@ -491,6 +491,7 @@ func (crSvc *clusterResourcesService) initModel() error { // init mongo options mongoOptions := &mongo.Options{ Hosts: strings.Split(crSvc.conf.Mongo.Address, ","), + Replicaset: crSvc.conf.Mongo.Replicaset, ConnectTimeoutSeconds: int(crSvc.conf.Mongo.ConnectTimeout), AuthDatabase: crSvc.conf.Mongo.AuthDatabase, Database: crSvc.conf.Mongo.Database, diff --git a/bcs-services/cluster-resources/go.mod b/bcs-services/cluster-resources/go.mod index 91c121132c..e92080c06f 100644 --- a/bcs-services/cluster-resources/go.mod +++ b/bcs-services/cluster-resources/go.mod @@ -40,7 +40,7 @@ replace ( require ( github.com/Masterminds/sprig/v3 v3.2.3 - github.com/Tencent/bk-bcs/bcs-common v0.0.0-20241015035856-99f8d8f45458 + github.com/Tencent/bk-bcs/bcs-common v0.0.0-20241212023042-2c0651f4eded github.com/TencentBlueKing/gopkg v1.1.0 github.com/TencentBlueKing/iam-go-sdk v0.1.6 // fork 自 https://github.com/signalfx/splunk-otel-go/tree/main/instrumentation/k8s.io/client-go/splunkclient-go diff --git a/bcs-services/cluster-resources/pkg/common/envs/envs.go b/bcs-services/cluster-resources/pkg/common/envs/envs.go index 9b0d477fa2..c037691b67 100644 --- a/bcs-services/cluster-resources/pkg/common/envs/envs.go +++ b/bcs-services/cluster-resources/pkg/common/envs/envs.go @@ -52,6 +52,7 @@ var ( BKIAMSystemID = envx.Get("BK_IAM_SYSTEM_ID", "") RedisPassword = envx.Get("REDIS_PASSWORD", "") MongoAddress = envx.Get("MONGO_ADDRESS", "") + MongoReplicaset = envx.Get("MONGO_REPLICASET", "") MongoUsername = envx.Get("MONGO_USERNAME", "") MongoPassword = envx.Get("MONGO_PASSWORD", "") ) diff --git a/bcs-services/cluster-resources/pkg/config/config.go b/bcs-services/cluster-resources/pkg/config/config.go index d0e0f16536..e0d4154ab8 100644 --- a/bcs-services/cluster-resources/pkg/config/config.go +++ b/bcs-services/cluster-resources/pkg/config/config.go @@ -74,6 +74,9 @@ func LoadConf(filePath string) (*ClusterResourcesConf, error) { if conf.Mongo.Address == "" { conf.Mongo.Address = envs.MongoAddress } + if conf.Mongo.Replicaset == "" { + conf.Mongo.Replicaset = envs.MongoReplicaset + } if conf.Mongo.Username == "" { conf.Mongo.Username = envs.MongoUsername } @@ -283,6 +286,7 @@ type RedisConf struct { // MongoConfig option for mongo type MongoConfig struct { Address string `json:"address" yaml:"address"` + Replicaset string `json:"replicaset" yaml:"replicaset"` ConnectTimeout uint `json:"connectTimeout" yaml:"connectTimeout"` AuthDatabase string `json:"authDatabase" yaml:"authDatabase"` Database string `json:"database" yaml:"database"`