From e44ac12cc8684e1db3cc650c6475e6730af9e553 Mon Sep 17 00:00:00 2001 From: carlchen Date: Mon, 9 Dec 2024 18:03:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20cmdb-synchronizer=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AEprojectcode?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bcs-bkcmdb-synchronizer.json.template | 3 +++ .../internal/pkg/handler/handler.go | 3 ++- .../internal/pkg/option/option.go | 18 ++++++++++++------ .../internal/pkg/syncer/syncer.go | 2 +- .../internal/synchronizer/synchronizer.go | 7 +++++++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/bcs-services/bcs-bkcmdb-synchronizer/config/bcs-bkcmdb-synchronizer.json.template b/bcs-services/bcs-bkcmdb-synchronizer/config/bcs-bkcmdb-synchronizer.json.template index badb7e5fe8..13bddeb0d0 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/config/bcs-bkcmdb-synchronizer.json.template +++ b/bcs-services/bcs-bkcmdb-synchronizer/config/bcs-bkcmdb-synchronizer.json.template @@ -45,5 +45,8 @@ "bk_username": "${cmdb_bkUsername}", "server": "${cmdb_server}", "debug": ${cmdb_debug} + }, + "shared_cluster": { + "annotation_key_proj_code": "${sharedCluster_annoKeyProjCode}" } } \ No newline at end of file diff --git a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/handler/handler.go b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/handler/handler.go index 1233c4a50e..bf0f2e98f8 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/handler/handler.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/handler/handler.go @@ -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, } diff --git a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/option/option.go b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/option/option.go index d47c9616e1..11157a548d 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/option/option.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/option/option.go @@ -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 @@ -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"` +} diff --git a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/syncer/syncer.go b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/syncer/syncer.go index 561bd0feb1..767d3279ab 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/syncer/syncer.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/syncer/syncer.go @@ -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) diff --git a/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go b/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go index 084fbf7ee5..3abf7b6862 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go @@ -124,6 +124,7 @@ func (s *Synchronizer) Init() { blog.Errorf("init mq failed, err: %s", err.Error()) } + s.initSharedClusterConf() } func (s *Synchronizer) initTlsConfig() error { @@ -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() { From d93d837e5f31b7923b43403aae83707b3feeba4b Mon Sep 17 00:00:00 2001 From: carlchen Date: Tue, 17 Dec 2024 20:29:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20cmdb-synchronizer=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AEprojectcode?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bcs-bkcmdb-synchronizer.json.template | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install/conf/bcs-services/bcs-bkcmdb-synchronizer/bcs-bkcmdb-synchronizer.json.template b/install/conf/bcs-services/bcs-bkcmdb-synchronizer/bcs-bkcmdb-synchronizer.json.template index badb7e5fe8..13bddeb0d0 100644 --- a/install/conf/bcs-services/bcs-bkcmdb-synchronizer/bcs-bkcmdb-synchronizer.json.template +++ b/install/conf/bcs-services/bcs-bkcmdb-synchronizer/bcs-bkcmdb-synchronizer.json.template @@ -45,5 +45,8 @@ "bk_username": "${cmdb_bkUsername}", "server": "${cmdb_server}", "debug": ${cmdb_debug} + }, + "shared_cluster": { + "annotation_key_proj_code": "${sharedCluster_annoKeyProjCode}" } } \ No newline at end of file