Skip to content

Commit

Permalink
feat: cmdb-synchronizer支持自定义配置projectcode注解
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyudeqiu committed Dec 3, 2024
1 parent b4d9375 commit 06d6386
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
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 @@ -2781,7 +2781,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 @@ -365,7 +365,7 @@ func (s *Syncer) SyncNamespaces(cluster *cmp.Cluster, bkCluster *bkcmdbkube.Clus
}
} else {
bizid := bkCluster.BizID
if projectCode, ok := v.Data.Annotations["io.tencent.bcs.projectcode"]; ok {
if projectCode, ok := v.Data.Annotations[s.BkcmdbSynchronizerOption.SharedCluster.AnnotationKeyProjCode]; ok {
gpr := pmp.GetProjectRequest{
ProjectIDOrCode: projectCode,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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 @@ -168,6 +169,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

0 comments on commit 06d6386

Please sign in to comment.