feat: bcs-common mongodb client支持配置replicaset #3632
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
当前,bcs 代码层面不支持配置副本集名称。在连接副本集模式下的 MongoDB 时,若副本集名称为默认的
rs0
,连接正常;但当副本集名称为其他值时,连接会出现异常,报认证失败的错误。其他服务都依赖bcs-common下的mongodb client,需要先在client支持配置。
修改如下:
bcs-common/pkg/odm/drivers/mongo/mongo.go
Options
中增加ReplicaSet
字段。bcs-common
中的NewDB
函数中,增加兼容性处理。当Replicaset
字段为空字符串时,客户端在创建时不指定replicaset
,与原先未配置replicaset
字段时的行为保持一致,这样可以确保,在最小改动各个模块代码的同时,现有配置不会受到影响。