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

fix: conditions for select registercenter instance from db #6445

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
18 changes: 16 additions & 2 deletions internal/apps/msp/resource/deploy/handlers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

"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"
Expand All @@ -33,6 +31,7 @@
"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 {
Expand Down Expand Up @@ -141,6 +140,21 @@
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": "N",
CeerDecy marked this conversation as resolved.
Show resolved Hide resolved
}
instance, ok, err := h.InstanceDb.First(where)
if err != nil {
return nil, false, err

Check warning on line 153 in internal/apps/msp/resource/deploy/handlers/mysql/mysql.go

View check run for this annotation

Codecov / codecov/patch

internal/apps/msp/resource/deploy/handlers/mysql/mysql.go#L153

Added line #L153 was not covered by tests
}
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)
Expand Down
37 changes: 37 additions & 0 deletions internal/apps/msp/resource/deploy/handlers/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ package mysql

import (
"encoding/json"
"reflect"
"testing"

"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"

"bou.ke/monkey"
)

func TestTryReadFile(t *testing.T) {
Expand Down Expand Up @@ -59,3 +64,35 @@ 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",
},
}

monkey.PatchInstanceMethod(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
})

_, _, _ = p.CheckIfNeedTmcInstance(req, info)
}
1 change: 1 addition & 0 deletions internal/tools/orchestrator/dbclient/addon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
var instance AddonInstance
if err := db.Where("addon_name = ?", addonName).
Where("az = ?", cluster).
Where("status = ?", apistructs.AddonAttached).

Check warning on line 121 in internal/tools/orchestrator/dbclient/addon_instance.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/orchestrator/dbclient/addon_instance.go#L121

Added line #L121 was not covered by tests
Where("is_deleted = ?", apistructs.AddonNotDeleted).
First(&instance).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
Expand Down
2 changes: 2 additions & 0 deletions internal/tools/orchestrator/services/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3145,8 +3145,10 @@
createItem := needDeployAddons[index]
switch v.AddonName {
case RegisterCenterAddon:
logrus.Infof("register-center version: [%s]->[%s] in cluster: %s", createItem.Options["version"], regVersion, req.ClusterName)

Check warning on line 3148 in internal/tools/orchestrator/services/addon/addon.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/orchestrator/services/addon/addon.go#L3148

Added line #L3148 was not covered by tests
createItem.Options["version"] = regVersion
case ConfigCenterAddon:
logrus.Infof("config-center version: [%s]->[%s] in cluster: %s", createItem.Options["version"], confVersion, req.ClusterName)

Check warning on line 3151 in internal/tools/orchestrator/services/addon/addon.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/orchestrator/services/addon/addon.go#L3151

Added line #L3151 was not covered by tests
createItem.Options["version"] = confVersion
}
instanceRes, err := a.AttachAndCreate(&createItem)
Expand Down
Loading