Skip to content

Commit

Permalink
feat: cluster addon reset to mse-addon if it has mse nacos (erda-proj…
Browse files Browse the repository at this point in the history
…ect#6424)

* fix: mse nacos bind registercenter

* feat: config-center reset addon

* fix: cluster addon interlink without nacos

* polish: remove useless code

* polish: remove useless code

* feat: add new config-center version: 2.0.0

* polish: set plan as variable and remove useless service

* feat: no need mse-nacos username and password

* polish: specify column names

* fix: pass test cover
  • Loading branch information
CeerDecy authored Aug 20, 2024
1 parent 305e368 commit c315ced
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .erda/migrations/msp/20240809-mse-nacos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INSERT INTO `tb_tmc` (`id`, `name`, `engine`, `service_type`, `deploy_mode`, `create_time`, `update_time`, `is_deleted`) VALUES (23,'MSE-Nacos','mse-nacos','ADDON','SAAS','2024-07-09 17:00:00','2024-07-09 17:00:00','N');

INSERT INTO `tb_tmc_version` (`id`, `engine`, `version`, `release_id`, `create_time`, `update_time`, `is_deleted`) VALUES (31,'mse-nacos','1.0.0',NULL,'2024-07-09 17:00:00','2024-07-09 17:00:00','N');
1 change: 1 addition & 0 deletions .erda/migrations/msp/20240812-insert-config-center.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `tb_tmc_version` (`id`, `engine`, `version`, `release_id`, `create_time`, `update_time`, `is_deleted`) VALUES(32,'config-center','2.0.0',NULL,'2024-08-12 14:30:00','2024-08-12 14:30:00','N')
1 change: 1 addition & 0 deletions cmd/erda-server/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ erda.msp.resource.deploy.handlers.apigateway:
http_port: "${DICE_HTTP_PORT}"
https_port: "${DICE_HTTPS_PORT}"
erda.msp.resource.deploy.handlers.configcenter:
erda.msp.resource.deploy.handlers.externalprovider:
erda.msp.resource.deploy.handlers.etcd:
erda.msp.resource.deploy.handlers.jvmprofiler:
erda.msp.resource.deploy.handlers.loganalytics:
Expand Down
1 change: 1 addition & 0 deletions cmd/erda-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ import (
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/apigateway"
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/configcenter"
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/etcd"
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/externalprovider"
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/jvmprofiler"
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/loganalytics"
_ "github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers/loges"
Expand Down
2 changes: 2 additions & 0 deletions cmd/orchestrator/conf/i18n/orchestrator-log-trans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ zh:
如果已创建, 请检查制品文件中 addonName 是否未匹配
AddonTypeDoseNoExist: "不存在该类型 addon: %s, 请检查 dice.yml 中 addon 部分是否正确"
NoRegisterCenterFound: "没有找到已部署的注册中心或dice.yaml中的注册中心版本,请先部署或者在dice.yaml中配置好注册中心"
AddonVersionDoseNoExist: "不存在该版本 addon: %s 版本: %s, 推荐使用 %s 版本"
AddonDefaultVersionDoseNoExist: "不存在默认版本 addon: %s, 请声明addon具体版本"
AddonPlanNotSupport: "addon %s 不支持当前的部署规格: %s, 请检查 dice.yml 中 addon 部分是否正确"
Expand All @@ -34,6 +35,7 @@ en:
If the addon has been created, please check the addonName in your release file
AddonTypeDoseNoExist: "The addon type %s dose not exist, please check it in your release file"
NoRegisterCenterFound: "No deployed register-center found or no register-center version specified in 'dice.yaml'. Please deploy a register-center first or configure it in 'dice.yaml'."
AddonVersionDoseNoExist: "The addon %s version %s dose not exist, The recommended version is: %s"
AddonDefaultVersionDoseNoExist: "Default version of addon %s does not exist, please declare a specific version of addon"
AddonPlanNotSupport: "addon %s is not supported by the current deployment plan: %s, please check it in your release file"
Expand Down
3 changes: 3 additions & 0 deletions internal/apps/msp/resource/deploy/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (p *provider) deploy(req handlers.ResourceDeployRequest) (*handlers.Resourc
}
}()

// if use mse or other, it will reset addons to mse-nacos
handler.ResetAddons(resourceInfo, clusterConfig)

for name, addon := range resourceInfo.Dice.AddOns {
if !isNeedDeployGatewayDependedAddon(resourceInfo.Spec.Type, resourceInfo.Spec.Name, clusterConfig) {
// 部署的是 api-gateway 且网关用 MSE, 则无需部署 网关 api-gateway 对应的 dice.yml 中依赖的 addons (postgresql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/erda-project/erda/internal/apps/msp/instance/db"
"github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers"
"github.com/erda-project/erda/internal/apps/msp/resource/utils"
"github.com/erda-project/erda/pkg/parser/diceyml"
)

func (p *provider) IsMatch(tmc *db.Tmc) bool {
Expand Down Expand Up @@ -106,3 +107,22 @@ func (p *provider) deleteDefaultConfigFromNacos(clusterName, addr, user, pwd, na
nacosClient := utils.NewNacosClient(clusterName, addr, user, pwd)
nacosClient.DeleteConfig(namespaceId, groupName)
}

func (p *provider) ResetAddons(info *handlers.ResourceInfo, clusterConfig map[string]string) {

if _, ok := clusterConfig[handlers.MseNacosHost]; !ok {
return
}
if _, ok := clusterConfig[handlers.MseNacosPort]; !ok {
return
}
info.Dice.AddOns = make(diceyml.AddOns)
info.Dice.AddOns[handlers.ResourceMSENacos] = &diceyml.AddOn{
Plan: handlers.PlanBasicMseNacos,
Options: map[string]string{
"version": "1.0.0",
handlers.MseNacosHost: clusterConfig[handlers.MseNacosHost],
handlers.MseNacosPort: clusterConfig[handlers.MseNacosPort],
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package externalprovider

import (
"github.com/erda-project/erda/internal/apps/msp/instance/db"
"github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers"
)

const (
MseNacosHost = "MS_NACOS_HOST"
MseNacosPort = "MS_NACOS_PORT"
)

// TODO it will support like "TSE" "HSE"
var matches = []string{handlers.ResourceMSENacos}

func (p *provider) IsMatch(tmc *db.Tmc) bool {
for _, res := range matches {
if res == tmc.Engine {
return true
}
}
return false
}

func (p *provider) CheckIfHasCustomConfig(clusterConfig map[string]string) (map[string]string, bool) {
nacosHost, ok := clusterConfig[MseNacosHost]
if !ok {
return nil, false
}

nacosPort, ok := clusterConfig[MseNacosPort]
if !ok {
return nil, false
}

return map[string]string{
"NACOS_HOST": nacosHost,
"NACOS_PORT": nacosPort,
"NACOS_ADDRESS": nacosHost + ":" + nacosPort,
}, true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package externalprovider

import (
"github.com/jinzhu/gorm"

"github.com/erda-project/erda-infra/base/logs"
"github.com/erda-project/erda-infra/base/servicehub"
"github.com/erda-project/erda/internal/apps/msp/resource/deploy/handlers"
)

type config struct {
}

// +provider
type provider struct {
*handlers.DefaultDeployHandler
Cfg *config
Log logs.Logger
DB *gorm.DB `autowired:"mysql-client"`
}

func (p *provider) Init(ctx servicehub.Context) error {
p.DefaultDeployHandler = handlers.NewDefaultHandler(p.DB, p.Log)
return nil
}

func init() {
servicehub.Register("erda.msp.resource.deploy.handlers.externalprovider", &servicehub.Spec{
Services: []string{
"erda.msp.resource.deploy.handlers.externalprovider",
},
Description: "erda.msp.resource.deploy.handlers.externalprovider",
ConfigFunc: func() interface{} {
return &config{}
},
Creator: func() servicehub.Provider {
return &provider{}
},
})
}
14 changes: 14 additions & 0 deletions internal/apps/msp/resource/deploy/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ const (
ResourceMonitorZk = "monitor-zk"
ResourceServiceMesh = "service-mesh"
ResourceLogService = "log-service"
// ResourceMSENacos external nacos from mse, deploy by [external provider]
ResourceMSENacos = "mse-nacos"
)

const (
MseNacosHost = "MS_NACOS_HOST"
MseNacosPort = "MS_NACOS_PORT"
)

const (
PlanBasicMseNacos = "mse-nacos:basic"
)

const (
Expand Down Expand Up @@ -127,6 +138,7 @@ type ResourceDeployHandler interface {
UnDeploy(tmcInstance *db.Instance) error
GetRelationResourceIds(parentId string) []string
DeleteRequestRelation(parentId string, childId string) error
ResetAddons(info *ResourceInfo, config map[string]string)
}

type DefaultDeployHandler struct {
Expand All @@ -140,6 +152,8 @@ type DefaultDeployHandler struct {
Log logs.Logger
}

func (h *DefaultDeployHandler) ResetAddons(info *ResourceInfo, config map[string]string) {}

func (h *DefaultDeployHandler) DeleteRequestRelation(parentId string, childId string) error {
err := h.TmcRequestRelationDb.DeleteRequestRelation(parentId, childId)
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,22 @@ func (p *provider) DoApplyTmcInstanceTenant(req *handlers.ResourceDeployRequest,
resultConfig["PUBLIC_HOST"] = str
return resultConfig, nil
}

func (p *provider) ResetAddons(info *handlers.ResourceInfo, clusterConfig map[string]string) {

if _, ok := clusterConfig[handlers.MseNacosHost]; !ok {
return
}
if _, ok := clusterConfig[handlers.MseNacosPort]; !ok {
return
}
info.Dice.AddOns = make(diceyml.AddOns)
info.Dice.AddOns[handlers.ResourceMSENacos] = &diceyml.AddOn{
Plan: handlers.PlanBasicMseNacos,
Options: map[string]string{
"version": "1.0.0",
handlers.MseNacosHost: clusterConfig[handlers.MseNacosHost],
handlers.MseNacosPort: clusterConfig[handlers.MseNacosPort],
},
}
}
14 changes: 14 additions & 0 deletions internal/tools/orchestrator/dbclient/addon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ func (db *DBClient) GetAddonInstance(id string) (*AddonInstance, error) {
return &instance, nil
}

func (db *DBClient) GetAddonInstanceByNameAndCluster(addonName, cluster string) (*AddonInstance, error) {
var instance AddonInstance
if err := db.Where("name = ?", addonName).
Where("az = ?", cluster).
Where("is_deleted = ?", apistructs.AddonNotDeleted).
First(&instance).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
return nil, nil
}
return nil, err
}
return &instance, nil
}

// GetInstancesByIDs 根据 ID 查询实例
func (db *DBClient) GetInstancesByIDs(ids []string) (*[]AddonInstance, error) {
var instances []AddonInstance
Expand Down
Loading

0 comments on commit c315ced

Please sign in to comment.