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": apistructs.AddonNotDeleted,
}
instance, ok, err := h.InstanceDb.First(where)
if err != nil {
return nil, false, err
}

Check warning on line 154 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-L154

Added lines #L153 - L154 were 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
40 changes: 40 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,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) {
Expand Down Expand Up @@ -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)
}
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 @@ -3167,8 +3167,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 3170 in internal/tools/orchestrator/services/addon/addon.go

View check run for this annotation

Codecov / codecov/patch

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

Added line #L3170 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 3173 in internal/tools/orchestrator/services/addon/addon.go

View check run for this annotation

Codecov / codecov/patch

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

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