Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cluster-manager新增泳道特性 #3670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bcs-services/bcs-cluster-manager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager
go 1.20

replace (
github.com/Tencent/bk-bcs/bcs-common => ../../bcs-common
github.com/Tencent/bk-bcs/bcs-common => github.com/LidolLxf/bk-bcs/bcs-common v0.0.0-20250115101422-10b01a987a53
k8s.io/api => k8s.io/api v0.26.1
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.1
k8s.io/apimachinery => k8s.io/apimachinery v0.26.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (da *DeleteVirtualAction) getClusterInfo() error {

func (da *DeleteVirtualAction) cleanLocalInformation() error {
// async delete cluster dependency info
go asyncDeleteImportedClusterInfo(context.Background(), da.model, da.cluster)
go asyncDeleteImportedClusterInfo(da.ctx, da.model, da.cluster)

// finally clean cluster
da.cluster.Status = common.StatusDeleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (ca *CreateAction) validate() error {
return err
}

proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ca.req.ProjectID, true)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ca.ctx, ca.req.ProjectID, true)
if errLocal == nil {
ca.project = proInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (da *DeleteAction) validate() error {

da.template = template

proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(da.req.ProjectID, true)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(da.ctx, da.req.ProjectID, true)
if errLocal == nil {
da.project = proInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (ua *UpdateAction) validate() error {
return err
}

proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ua.req.ProjectID, true)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ua.ctx, ua.req.ProjectID, true)
if errLocal == nil {
ua.project = proInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (ca *CreateAction) validate() error {
return err
}

proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ca.req.ProjectID, true)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ca.ctx, ca.req.ProjectID, true)
if errLocal == nil {
ca.project = proInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (da *DeleteAction) validate() error {

da.template = template

proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(da.req.ProjectID, true)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(da.ctx, da.req.ProjectID, true)
if errLocal == nil {
da.project = proInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (ga *GetProjectResourceQuotaUsageAction) validate() error {
}

// check projectId or Code
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ga.req.GetProjectID(), false)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ga.ctx, ga.req.GetProjectID(), false)
if errLocal != nil {
return errLocal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (ga *GetProviderResourceUsageAction) getBizInfoByPools() error {
continue
}

proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(cls.ProjectID, true)
proInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(ga.ctx, cls.ProjectID, true)
if errLocal != nil {
blog.Errorf("getProviderDevicePools GetProjectInfo[%s] failed: %v",
group.ClusterID, errLocal)
Expand Down
57 changes: 19 additions & 38 deletions bcs-services/bcs-cluster-manager/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ import (
commonutil "github.com/Tencent/bk-bcs/bcs-common/common/util"
"github.com/Tencent/bk-bcs/bcs-common/common/version"
"github.com/Tencent/bk-bcs/bcs-common/pkg/auth/iam"
"github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapi/bcsproject"
"github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapi/clustermanager"
"github.com/Tencent/bk-bcs/bcs-common/pkg/discovery"
"github.com/Tencent/bk-bcs/bcs-common/pkg/header"
"github.com/Tencent/bk-bcs/bcs-common/pkg/i18n"
"github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers"
"github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers/mongo"
"github.com/Tencent/bk-bcs/bcs-common/pkg/otel/trace/constants"
"github.com/Tencent/bk-bcs/bcs-common/pkg/otel/trace/micro"
"github.com/Tencent/bk-bcs/bcs-services/pkg/bcs-auth/middleware"
restful "github.com/emicklei/go-restful"
Expand All @@ -66,7 +69,6 @@ import (
cmcommon "github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/common"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/commonhandler"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/daemon"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/discovery"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/handler"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/lock"
etcdlock "github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/lock/etcd"
Expand All @@ -79,7 +81,6 @@ import (
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/cmdb"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/encrypt"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/gse"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/install/addons"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/install/helm"
installTypes "github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/install/types"
"github.com/Tencent/bk-bcs/bcs-services/bcs-cluster-manager/internal/remote/job"
Expand Down Expand Up @@ -412,18 +413,6 @@ func (cm *ClusterManager) initRemoteClient() error { // nolint
if err != nil {
return err
}
// init addons client
err = addons.SetAddonsClient(&installTypes.Options{
Enable: cm.opt.Helm.Enable,
GateWay: cm.opt.Helm.GateWay,
Token: cm.opt.Helm.Token,
Module: cm.opt.Helm.Module,
EtcdRegistry: cm.microRegistry,
ClientTLSConfig: cm.clientTLSConfig,
})
if err != nil {
return err
}

// init encrypt client
err = encrypt.SetEncryptClient(cm.opt.Encrypt)
Expand Down Expand Up @@ -708,7 +697,12 @@ func (cm *ClusterManager) initRegistry() error {

// initDiscovery discovery client
func (cm *ClusterManager) initDiscovery() {
cm.disc = discovery.NewModuleDiscovery(cmcommon.ClusterManagerServiceDomain, cm.microRegistry)
if !discovery.UseServiceDiscovery() {
cm.disc = discovery.NewModuleDiscovery(cmcommon.ClusterManagerServiceDomain, cm.microRegistry)
clustermanager.SetClientConfig(cm.tlsConfig, cm.disc)
} else {
clustermanager.SetClientConfig(cm.tlsConfig, nil)
}
blog.Infof("init discovery for cluster manager successfully")

// enable discovery resource module
Expand All @@ -725,13 +719,17 @@ func (cm *ClusterManager) initDiscovery() {

// enable discovery project module
if cm.opt.ProjectManager.Enable {
cm.projectDisc = discovery.NewModuleDiscovery(cm.opt.ProjectManager.Module, cm.microRegistry)
blog.Infof("init discovery for project manager successfully")

project.SetProjectClient(&project.Options{
Module: cm.opt.ProjectManager.Module,
TLSConfig: cm.clientTLSConfig,
}, cm.projectDisc)
})
if !discovery.UseServiceDiscovery() {
cm.projectDisc = discovery.NewModuleDiscovery(cm.opt.ProjectManager.Module, cm.microRegistry)
blog.Infof("init discovery for project manager successfully")
bcsproject.SetClientConfig(cm.clientTLSConfig, cm.projectDisc)
} else {
bcsproject.SetClientConfig(cm.clientTLSConfig, nil)
}
}
}

Expand Down Expand Up @@ -802,26 +800,10 @@ func (cm *ClusterManager) initTunnelServer(router *mux.Router) error {
return nil
}

// CustomMatcher for http header
func CustomMatcher(key string) (string, bool) {
switch key {
case "X-Request-Id":
return "X-Request-Id", true
case middleware.CustomUsernameHeaderKey:
return middleware.CustomUsernameHeaderKey, true
case middleware.InnerClientHeaderKey:
return middleware.InnerClientHeaderKey, true
case constants.Traceparent:
return constants.GrpcTraceparent, true
default:
return runtime.DefaultHeaderMatcher(key)
}
}

// init http grpc gateway
func (cm *ClusterManager) initHTTPGateway(router *mux.Router) error {
gwmux := runtime.NewServeMux(
runtime.WithIncomingHeaderMatcher(CustomMatcher),
runtime.WithIncomingHeaderMatcher(header.CustomHeaderMatcher),
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{
OrigName: true,
EmitDefaults: true,
Expand Down Expand Up @@ -1104,7 +1086,6 @@ func (cm *ClusterManager) close() {
closeCtx, closeCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer closeCancel()
helm.GetHelmManagerClient().Stop()
addons.GetAddonsClient().Stop()
cm.extraServer.Shutdown(closeCtx) // nolint
cm.httpServer.Shutdown(closeCtx) // nolint
cm.daemon.Stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func InstallWatchComponentByHelm(ctx context.Context, projectID,
blog.Errorf("InstallWatchComponentByHelm[%s] GetWatchInstaller failed: %v", taskID, err)
return err
}
err = installer.Install(clusterID, values)
err = installer.Install(ctx, clusterID, values)
if err != nil {
blog.Errorf("InstallWatchComponentByHelm[%s] Install failed: %v", taskID, err)
return err
Expand All @@ -166,7 +166,7 @@ func DeleteWatchComponentByHelm(ctx context.Context, projectID,
blog.Errorf("DeleteWatchComponentByHelm[%s] GetWatchInstaller failed: %v", traceID, err)
return err
}
err = install.Uninstall(clusterID)
err = install.Uninstall(ctx, clusterID)
if err != nil {
blog.Errorf("DeleteWatchComponentByHelm[%s] Uninstall failed: %v", traceID, err)
return err
Expand All @@ -178,7 +178,7 @@ func DeleteWatchComponentByHelm(ctx context.Context, projectID,

err = loop.LoopDoFunc(timeContext, func() error {
var exist bool
exist, err = install.IsInstalled(clusterID)
exist, err = install.IsInstalled(ctx, clusterID)
if err != nil {
blog.Errorf("DeleteWatchComponentByHelm[%s] failed[%s:%s]: %v", traceID, projectID, clusterID, err)
return nil
Expand Down Expand Up @@ -260,7 +260,7 @@ func InstallImagePullSecretByAddon(ctx context.Context, projectID, clusterID str
blog.Errorf("InstallImagePullSecretByAddon[%s] GetAddonInstaller failed: %v", taskID, err)
return err
}
err = installer.Install(clusterID, "")
err = installer.Install(ctx, clusterID, "")
if err != nil {
blog.Errorf("InstallImagePullSecretByAddon[%s] Install failed: %v", taskID, err)
return err
Expand All @@ -280,7 +280,7 @@ func DeleteImagePullSecretByAddon(ctx context.Context, projectID,
blog.Errorf("DeleteImagePullSecretByAddon[%s] GetAddonInstaller failed: %v", traceID, err)
return err
}
err = install.Uninstall(clusterID)
err = install.Uninstall(ctx, clusterID)
if err != nil {
blog.Errorf("DeleteImagePullSecretByAddon[%s] Uninstall failed: %v", traceID, err)
return err
Expand Down Expand Up @@ -474,7 +474,7 @@ func ensureVclusterWithInstaller(ctx context.Context, info *VclusterInfo) error
blog.Errorf("ensureVclusterWithInstaller[%s] GetVclusterInstaller failed: %v", taskID, err)
return err
}
installed, err := installer.IsInstalled(info.SrcClusterID)
installed, err := installer.IsInstalled(ctx, info.SrcClusterID)
if err != nil {
blog.Errorf("ensureVclusterWithInstaller[%s] IsInstalled failed: %v", taskID, err)
return err
Expand All @@ -498,17 +498,17 @@ func ensureVclusterWithInstaller(ctx context.Context, info *VclusterInfo) error

// install or upgrade
if installed {
if errUpgrade := installer.Upgrade(info.SrcClusterID, values); errUpgrade != nil {
if errUpgrade := installer.Upgrade(ctx, info.SrcClusterID, values); errUpgrade != nil {
return fmt.Errorf("upgrade app failed, err %s", errUpgrade)
}
} else {
if errInstall := installer.Install(info.SrcClusterID, values); errInstall != nil {
if errInstall := installer.Install(ctx, info.SrcClusterID, values); errInstall != nil {
return fmt.Errorf("install app failed, err %s", errInstall)
}
}

// check status
ok, err := installer.CheckAppStatus(info.SrcClusterID, time.Minute*10, false)
ok, err := installer.CheckAppStatus(ctx, info.SrcClusterID, time.Minute*10, false)
if err != nil {
return fmt.Errorf("check app status failed, err %s", err)
}
Expand Down Expand Up @@ -596,7 +596,7 @@ func DeleteVclusterComponentByHelm(ctx context.Context, info *VclusterInfo) erro
blog.Errorf("DeleteVclusterComponentByHelm[%s] GetVclusterInstaller failed: %v", taskID, err)
return err
}
err = install.Uninstall(info.SrcClusterID)
err = install.Uninstall(ctx, info.SrcClusterID)
if err != nil {
blog.Errorf("DeleteVclusterComponentByHelm[%s] Uninstall failed: %v", taskID, err)
return err
Expand All @@ -607,7 +607,7 @@ func DeleteVclusterComponentByHelm(ctx context.Context, info *VclusterInfo) erro
defer cancel()

err = loop.LoopDoFunc(timeContext, func() error {
exist, errInstall := install.IsInstalled(info.SrcClusterID)
exist, errInstall := install.IsInstalled(ctx, info.SrcClusterID)
if errInstall != nil {
blog.Errorf("DeleteVclusterComponentByHelm[%s] failed[%s:%s]: %v", taskID, info.ProjectID,
info.SrcClusterID, errInstall)
Expand Down Expand Up @@ -749,7 +749,7 @@ func ensureAutoScalerWithInstaller(ctx context.Context, nodeGroups []proto.NodeG
blog.Errorf("ensureAutoScalerWithInstaller[%s] CreateClusterNamespace failed: %v", taskID, err)
}

installed, err := installer.IsInstalled(as.ClusterID)
installed, err := installer.IsInstalled(ctx, as.ClusterID)
if err != nil {
blog.Errorf("ensureAutoScalerWithInstaller IsInstalled failed: %v", err)
return err
Expand All @@ -776,14 +776,14 @@ func ensureAutoScalerWithInstaller(ctx context.Context, nodeGroups []proto.NodeG
}
// install or upgrade
if installed {
if err = installer.Upgrade(as.ClusterID, values); err != nil {
if err = installer.Upgrade(ctx, as.ClusterID, values); err != nil {
return fmt.Errorf("upgrade app failed, err %s", err)
}

cloudprovider.GetStorageModel().CreateTaskStepLogInfo(context.Background(),
taskID, stepName, "upgrade app successful")
} else {
if err = installer.Install(as.ClusterID, values); err != nil {
if err = installer.Install(ctx, as.ClusterID, values); err != nil {
return fmt.Errorf("install app failed, err %s", err)
}

Expand All @@ -793,7 +793,7 @@ func ensureAutoScalerWithInstaller(ctx context.Context, nodeGroups []proto.NodeG

// check status
var ok bool
ok, err = installer.CheckAppStatus(as.ClusterID, time.Minute*10, false)
ok, err = installer.CheckAppStatus(ctx, as.ClusterID, time.Minute*10, false)
if err != nil {
return fmt.Errorf("check app status failed, err %s", err)
}
Expand All @@ -814,11 +814,11 @@ func ensureAutoScalerWithInstaller(ctx context.Context, nodeGroups []proto.NodeG
return fmt.Errorf("transAutoScalingOptionToValues failed, err: %s", err)
}

if err = installer.Upgrade(as.ClusterID, values); err != nil {
if err = installer.Upgrade(ctx, as.ClusterID, values); err != nil {
return fmt.Errorf("upgrade app failed, err %s", err)
}
// check status
ok, errCheck := installer.CheckAppStatus(as.ClusterID, time.Minute*10, false)
ok, errCheck := installer.CheckAppStatus(ctx, as.ClusterID, time.Minute*10, false)
if errCheck != nil {
return fmt.Errorf("check app status failed, err %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *Daemon) reportClusterGroupNodeNum(error chan<- error) {
}

bizId := ""
pInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(group.ProjectID, true)
pInfo, errLocal := project.GetProjectManagerClient().GetProjectInfo(d.ctx, group.ProjectID, true)
if errLocal == nil {
bizId = pInfo.GetBusinessID()
}
Expand Down
Loading
Loading