From 02452d84063f319e92d1f4320ffa0329bb357df9 Mon Sep 17 00:00:00 2001 From: carlchen Date: Tue, 19 Nov 2024 20:32:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20cluster-manager=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 --- .../conf/bcs-cluster-manager.json.template | 3 +++ .../internal/actions/cluster/create_vcluster.go | 4 ++-- bcs-services/bcs-cluster-manager/internal/app/app.go | 8 ++++++++ .../bcs-cluster-manager/internal/options/options.go | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template b/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template index 6b5ea2ca80..98325a03fc 100644 --- a/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template +++ b/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template @@ -193,6 +193,9 @@ "enableInsTypeUsage": ${enableInsTypeUsage}, "enableAllocateCidr": ${enableAllocateCidr} }, + "sharedCluster": { + "annoKeyProjCode": "${bcsSharedClusterAnnoKeyProjCode}" + } "tagDepart": "${tagDepart}", "prefixVcluster": "${prefixVcluster}", "version": "${bcsClusterManagerVersion}", diff --git a/bcs-services/bcs-cluster-manager/internal/actions/cluster/create_vcluster.go b/bcs-services/bcs-cluster-manager/internal/actions/cluster/create_vcluster.go index f4f91f54b8..864334677d 100644 --- a/bcs-services/bcs-cluster-manager/internal/actions/cluster/create_vcluster.go +++ b/bcs-services/bcs-cluster-manager/internal/actions/cluster/create_vcluster.go @@ -186,11 +186,11 @@ func (ca *CreateVirtualClusterAction) validate() error { } if ca.req.Ns.Annotations == nil { ca.req.Ns.Annotations = map[string]string{ - utils.ProjectCode: ca.req.ProjectCode, + options.GetGlobalCMOptions().SharedCluster.AnnoKeyProjCode: ca.req.ProjectCode, utils.NamespaceCreator: ca.req.Creator, } } else { - ca.req.Ns.Annotations[utils.ProjectCode] = ca.req.ProjectCode + ca.req.Ns.Annotations[options.GetGlobalCMOptions().SharedCluster.AnnoKeyProjCode] = ca.req.ProjectCode ca.req.Ns.Annotations[utils.NamespaceCreator] = ca.req.Creator } diff --git a/bcs-services/bcs-cluster-manager/internal/app/app.go b/bcs-services/bcs-cluster-manager/internal/app/app.go index 08f57aceaa..5a2dc10072 100644 --- a/bcs-services/bcs-cluster-manager/internal/app/app.go +++ b/bcs-services/bcs-cluster-manager/internal/app/app.go @@ -865,6 +865,12 @@ func (cm *ClusterManager) initCommonHandler(router *mux.Router) error { return nil } +func (cm *ClusterManager) initSharedClusterConf() { + if cm.opt.SharedCluster.AnnoKeyProjCode == "" { + cm.opt.SharedCluster.AnnoKeyProjCode = utils.ProjectCode + } +} + // initHTTPService init http service func (cm *ClusterManager) initHTTPService() error { router := mux.NewRouter() @@ -1180,6 +1186,8 @@ func (cm *ClusterManager) Init() error { blog.Errorf("initCloudTemplateConfig failed: %v", err) } + // init shared cluster config + cm.initSharedClusterConf() // init metric, pprof cm.initExtraModules() // init system signal handler diff --git a/bcs-services/bcs-cluster-manager/internal/options/options.go b/bcs-services/bcs-cluster-manager/internal/options/options.go index 5040b61e51..4bb8f05d37 100644 --- a/bcs-services/bcs-cluster-manager/internal/options/options.go +++ b/bcs-services/bcs-cluster-manager/internal/options/options.go @@ -291,6 +291,11 @@ type DaemonConfig struct { EnableAllocateCidr bool `json:"enableAllocateCidr"` } +// SharedClusterConfig config for shared cluster +type SharedClusterConfig struct { + AnnoKeyProjCode string `json:"annoKeyProjCode"` +} + // ClusterManagerOptions options of cluster manager type ClusterManagerOptions struct { Etcd EtcdOption `json:"etcd"` @@ -325,6 +330,7 @@ type ClusterManagerOptions struct { TracingConfig conf.TracingConfig `json:"tracingConfig"` Encrypt encryptv2.Config `json:"encrypt"` Daemon DaemonConfig `json:"daemon"` + SharedCluster SharedClusterConfig `json:"sharedCluster"` ServerConfig ClientConfig } From 1047c46ff78d269e5141412629394c2cee2c5d84 Mon Sep 17 00:00:00 2001 From: carlchen Date: Thu, 12 Dec 2024 20:35:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20cluster-manager=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-cluster-manager/conf/bcs-cluster-manager.json.template | 2 +- .../bcs-cluster-manager/bcs-cluster-manager.json.template | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template b/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template index 98325a03fc..4c36e2a254 100644 --- a/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template +++ b/bcs-services/bcs-cluster-manager/conf/bcs-cluster-manager.json.template @@ -195,7 +195,7 @@ }, "sharedCluster": { "annoKeyProjCode": "${bcsSharedClusterAnnoKeyProjCode}" - } + }, "tagDepart": "${tagDepart}", "prefixVcluster": "${prefixVcluster}", "version": "${bcsClusterManagerVersion}", diff --git a/install/conf/bcs-services/bcs-cluster-manager/bcs-cluster-manager.json.template b/install/conf/bcs-services/bcs-cluster-manager/bcs-cluster-manager.json.template index 74f5c69bfe..c763f860f5 100644 --- a/install/conf/bcs-services/bcs-cluster-manager/bcs-cluster-manager.json.template +++ b/install/conf/bcs-services/bcs-cluster-manager/bcs-cluster-manager.json.template @@ -192,6 +192,9 @@ "enableInsTypeUsage": ${enableInsTypeUsage}, "enableAllocateCidr": ${enableAllocateCidr} }, + "sharedCluster": { + "annoKeyProjCode": "${bcsSharedClusterAnnoKeyProjCode}" + }, "tagDepart": "${tagDepart}", "prefixVcluster": "${prefixVcluster}", "version": "${bcsClusterManagerVersion}",