Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cmdb-synchronizer支持自定义配置projectcode注解 #3624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
"bk_username": "${cmdb_bkUsername}",
"server": "${cmdb_server}",
"debug": ${cmdb_debug}
},
"shared_cluster": {
"annotation_key_proj_code": "${sharedCluster_annoKeyProjCode}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,8 @@ func (b *BcsBkcmdbSynchronizerHandler) handleNamespaceCreate(
}

bizid := bkCluster.BizID
if projectCode, ok := namespace.Annotations["io.tencent.bcs.projectcode"]; ok {
annotationKey := b.Syncer.BkcmdbSynchronizerOption.SharedCluster.AnnotationKeyProjCode
if projectCode, ok := namespace.Annotations[annotationKey]; ok {
gpr := pmp.GetProjectRequest{
ProjectIDOrCode: projectCode,
}
Expand Down
18 changes: 12 additions & 6 deletions bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import "github.com/Tencent/bk-bcs/bcs-common/common/conf"

// BkcmdbSynchronizerOption options for CostManager
type BkcmdbSynchronizerOption struct {
Synchronizer SynchronizerConfig `json:"synchronizer" value:"synchronizer"`
Client ClientConfig `json:"client"`
Bcslog conf.LogConfig `json:"bcslog"`
Bcsapi BcsapiConfig `json:"bcsapi"`
RabbitMQ RabbitMQConfig `json:"rabbitmq"`
CMDB CMDBConfig `json:"cmdb"`
Synchronizer SynchronizerConfig `json:"synchronizer" value:"synchronizer"`
Client ClientConfig `json:"client"`
Bcslog conf.LogConfig `json:"bcslog"`
Bcsapi BcsapiConfig `json:"bcsapi"`
RabbitMQ RabbitMQConfig `json:"rabbitmq"`
CMDB CMDBConfig `json:"cmdb"`
SharedCluster SharedClusterConfig `json:"shared_cluster"`
}

// SynchronizerConfig synchronizer config
Expand Down Expand Up @@ -70,3 +71,8 @@ type CMDBConfig struct {
Server string `json:"server"`
Debug bool `json:"debug"`
}

// SharedClusterConfig shared cluster config
type SharedClusterConfig struct {
AnnotationKeyProjCode string `json:"annotation_key_proj_code"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (s *Syncer) SyncNamespaces(cluster *cmp.Cluster, bkCluster *bkcmdbkube.Clus

for k, v := range nsMap {
nsbizid := bkCluster.BizID
if projectCode, ok := v.Data.Annotations["io.tencent.bcs.projectcode"]; ok {
if projectCode, ok := v.Data.Annotations[s.BkcmdbSynchronizerOption.SharedCluster.AnnotationKeyProjCode]; ok {
bizid, errP := s.getBizidByProjectCode(projectCode)
if errP != nil {
blog.Errorf("get bizid by projectcode err: %v", errP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (s *Synchronizer) Init() {
blog.Errorf("init mq failed, err: %s", err.Error())
}

s.initSharedClusterConf()
}

func (s *Synchronizer) initTlsConfig() error {
Expand Down Expand Up @@ -171,6 +172,12 @@ func (s *Synchronizer) initMQ() error {
return nil
}

func (s *Synchronizer) initSharedClusterConf() {
if s.Syncer.BkcmdbSynchronizerOption.SharedCluster.AnnotationKeyProjCode == "" {
s.Syncer.BkcmdbSynchronizerOption.SharedCluster.AnnotationKeyProjCode = "io.tencent.bcs.projectcode"
}
}

// Run run the synchronizer
// nolint funlen
func (s *Synchronizer) Run() {
Expand Down
Loading