Skip to content

Commit

Permalink
feat: cmdb-synchronizer支持自定义配置projectcode注解 (#3624)
Browse files Browse the repository at this point in the history
* feat: cmdb-synchronizer支持自定义配置projectcode注解

* feat: cmdb-synchronizer支持自定义配置projectcode注解
  • Loading branch information
yuyudeqiu authored Dec 23, 2024
1 parent e63331a commit 86d5f22
Show file tree
Hide file tree
Showing 6 changed files with 28 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 @@ -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
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}"
}
}

0 comments on commit 86d5f22

Please sign in to comment.