From 06d638661ae1353fb4fb2f987a3af0bebf87a0ee Mon Sep 17 00:00:00 2001 From: carlchen Date: Wed, 20 Nov 2024 11:21:11 +0800 Subject: [PATCH] =?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 4b793da40a..ac82dffa25 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/handler/handler.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/handler/handler.go @@ -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, } 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 c32887c298..91bb0eca4c 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/syncer/syncer.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/pkg/syncer/syncer.go @@ -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, } diff --git a/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go b/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go index 4fdf41acec..8a893764b0 100644 --- a/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go +++ b/bcs-services/bcs-bkcmdb-synchronizer/internal/synchronizer/synchronizer.go @@ -121,6 +121,7 @@ func (s *Synchronizer) Init() { blog.Errorf("init mq failed, err: %s", err.Error()) } + s.initSharedClusterConf() } func (s *Synchronizer) initTlsConfig() error { @@ -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() {