Skip to content

Commit

Permalink
feat: cluster-resources支持配置mongodb副本集名称 (#3636) (#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyudeqiu authored Dec 18, 2024
1 parent 916976f commit 360457c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
1 change: 1 addition & 0 deletions bcs-services/cluster-resources/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func (crSvc *clusterResourcesService) initModel() error {
}
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,
Expand Down
103 changes: 50 additions & 53 deletions bcs-services/cluster-resources/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,45 @@ replace (

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230920065036-5ec367ec2378
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20241213022113-d2cc3e32d60c
github.com/TencentBlueKing/gopkg v1.1.0
github.com/TencentBlueKing/iam-go-sdk v0.1.5
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
// 待升级到 go1.18 后,可直接引用社区的包
github.com/adevjoe/opentelemetry-go-contrib/instrumentation/k8s.io/client-go v1.0.2
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/dustin/go-humanize v1.0.0
github.com/envoyproxy/protoc-gen-validate v1.0.2
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/fatih/structs v1.1.0
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
github.com/go-micro/plugins/v4/server/grpc v1.2.0
github.com/go-redis/cache/v8 v8.4.3
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.7.0
github.com/go-resty/resty/v2 v2.12.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/glog v1.1.0
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.3.1
github.com/golang/glog v1.2.0
github.com/golang/protobuf v1.5.4
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_golang v1.19.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802
go-micro.dev/v4 v4.10.2
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0
go.opentelemetry.io/otel v1.18.0
go.opentelemetry.io/otel/trace v1.18.0
go.uber.org/zap v1.19.1
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.28.0
Expand All @@ -103,47 +103,44 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220824120805-4b6e5c587895 // indirect
github.com/Tencent/bk-bcs/bcs-common/pkg/otel v0.0.0-20230606084703-25ffabad186a
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-acme/lego/v4 v4.4.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.0.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomodule/redigo v1.8.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
Expand All @@ -155,12 +152,10 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
Expand All @@ -171,22 +166,22 @@ require (
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/parnurzeal/gorequest v0.2.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/http-swagger v1.3.4
github.com/swaggo/swag v1.8.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand All @@ -198,19 +193,18 @@ require (
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc/examples v0.0.0-20211102180624-670c133e568e // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand All @@ -226,32 +220,34 @@ require (

require (
github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20230701022721-8cbd62252af8
github.com/TencentBlueKing/bk-audit-go-sdk v0.0.5 // indirect
github.com/TencentBlueKing/bk-audit-go-sdk v0.0.6 // indirect
)

require (
github.com/Tencent/bk-bcs/bcs-common/pkg/audit v0.0.0-20231031062827-2cd36075dfea
github.com/Tencent/bk-bcs/bcs-common/pkg/auth v0.0.0-20230921024236-fc3b5f7e6d87
github.com/Tencent/bk-bcs/bcs-scenarios/kourse v0.0.0-20231011121510-d30829b961ad
github.com/go-redis/redis/extra/redisotel/v8 v8.11.5
github.com/googleapis/gnostic v0.5.5
github.com/mitchellh/hashstructure/v2 v2.0.2
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.44.0
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98
k8s.io/apiextensions-apiserver v0.20.0
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237
k8s.io/apiextensions-apiserver v0.23.1
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-redis/redis/extra/rediscmd/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-migrate/migrate/v4 v4.16.2 // indirect
github.com/golang-migrate/migrate/v4 v4.17.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand All @@ -264,15 +260,16 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/signalfx/splunk-otel-go v1.4.0 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
k8s.io/cli-runtime v0.28.0 // indirect
k8s.io/component-base v0.28.0 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/kubernetes v0.0.0-00010101000000-000000000000 // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.2 // indirect
Expand Down
1 change: 1 addition & 0 deletions bcs-services/cluster-resources/pkg/common/envs/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
)
Expand Down
4 changes: 4 additions & 0 deletions bcs-services/cluster-resources/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -281,6 +284,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"`
Expand Down

0 comments on commit 360457c

Please sign in to comment.