diff --git a/internal/apps/msp/resource/deploy/handlers/mysql/mysql.go b/internal/apps/msp/resource/deploy/handlers/mysql/mysql.go index 8041d07235d..95795f035ff 100644 --- a/internal/apps/msp/resource/deploy/handlers/mysql/mysql.go +++ b/internal/apps/msp/resource/deploy/handlers/mysql/mysql.go @@ -22,8 +22,6 @@ import ( "github.com/pkg/errors" - "github.com/erda-project/erda/pkg/strutil" - "github.com/erda-project/erda/apistructs" conf "github.com/erda-project/erda/cmd/erda-server/conf/msp" "github.com/erda-project/erda/internal/apps/msp/instance/db" @@ -33,6 +31,7 @@ import ( "github.com/erda-project/erda/pkg/crypto/uuid" "github.com/erda-project/erda/pkg/mysqlhelper" "github.com/erda-project/erda/pkg/parser/diceyml" + "github.com/erda-project/erda/pkg/strutil" ) func (p *provider) IsMatch(tmc *db.Tmc) bool { @@ -141,6 +140,21 @@ func (h *provider) DoDeploy(serviceGroupDeployRequest interface{}, resourceInfo return h.DefaultDeployHandler.DoDeploy(serviceGroupDeployRequest, resourceInfo, tmcInstance, clusterConfig) } +func (h *provider) CheckIfNeedTmcInstance(req *handlers.ResourceDeployRequest, resourceInfo *handlers.ResourceInfo) (*db.Instance, bool, error) { + // mysql remove the `version` condition. because in the old cluster nacos[1.1.0] depend on mysql[5.7] but now depend on mysql[8.0] + var where = map[string]any{ + "engine": resourceInfo.TmcVersion.Engine, + "az": req.Az, + "status": handlers.TmcInstanceStatusRunning, + "is_deleted": apistructs.AddonNotDeleted, + } + instance, ok, err := h.InstanceDb.First(where) + if err != nil { + return nil, false, err + } + return instance, !ok, nil +} + func (p *provider) DoPostDeployJob(tmcInstance *db.Instance, serviceGroupDeployResult interface{}, clusterConfig map[string]string) (map[string]string, error) { serviceGroup := serviceGroupDeployResult.(*apistructs.ServiceGroup) mysqlMap := ParseResp2MySQLDtoMap(tmcInstance, serviceGroup) diff --git a/internal/apps/msp/resource/deploy/handlers/mysql/mysql_test.go b/internal/apps/msp/resource/deploy/handlers/mysql/mysql_test.go index 8a9743b0d66..bd1e7489816 100644 --- a/internal/apps/msp/resource/deploy/handlers/mysql/mysql_test.go +++ b/internal/apps/msp/resource/deploy/handlers/mysql/mysql_test.go @@ -16,10 +16,16 @@ package mysql import ( "encoding/json" + "reflect" "testing" + "github.com/agiledragon/gomonkey/v2" + "github.com/stretchr/testify/assert" + "github.com/erda-project/erda/apistructs" "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" ) func TestTryReadFile(t *testing.T) { @@ -59,3 +65,37 @@ func TestParseResp2MySQLDtoMap(t *testing.T) { t.Fatal("failed to parse") } } + +func TestCheckIfNeedTmcInstance(t *testing.T) { + p := &provider{ + DefaultDeployHandler: &handlers.DefaultDeployHandler{ + InstanceDb: &db.InstanceDB{}, + }, + } + req := &handlers.ResourceDeployRequest{ + Engine: "mysql", + Uuid: utils.GetRandomId(), + Az: "test-cluster", + } + info := &handlers.ResourceInfo{ + Tmc: &db.Tmc{}, + TmcVersion: &db.TmcVersion{ + Engine: "mysql", + }, + } + + applyFunc := gomonkey.ApplyMethod(reflect.TypeOf(p.InstanceDb), "First", func(DB *db.InstanceDB, where map[string]any) (*db.Instance, bool, error) { + return &db.Instance{ + Engine: "mysql", + Version: "9.0", + ReleaseID: "i am release id!", + Status: "RUNNING", + Az: "test-cluster", + Config: "", + }, false, nil + }) + defer applyFunc.Reset() + + _, _, err := p.CheckIfNeedTmcInstance(req, info) + assert.NoError(t, err) +} diff --git a/internal/tools/orchestrator/services/addon/addon.go b/internal/tools/orchestrator/services/addon/addon.go index 956771bfa09..e36dba49064 100644 --- a/internal/tools/orchestrator/services/addon/addon.go +++ b/internal/tools/orchestrator/services/addon/addon.go @@ -3167,8 +3167,10 @@ func (a *Addon) deployAddons(req *apistructs.AddonCreateRequest, deploys []dbcli createItem := needDeployAddons[index] switch v.AddonName { case RegisterCenterAddon: + logrus.Infof("register-center version: [%s]->[%s] in cluster: %s", createItem.Options["version"], regVersion, req.ClusterName) createItem.Options["version"] = regVersion case ConfigCenterAddon: + logrus.Infof("config-center version: [%s]->[%s] in cluster: %s", createItem.Options["version"], confVersion, req.ClusterName) createItem.Options["version"] = confVersion } instanceRes, err := a.AttachAndCreate(&createItem)