diff --git a/dbm-services/mysql/db-simulation/app/config/config.go b/dbm-services/mysql/db-simulation/app/config/config.go index 85a6f46dde..12f6bef7ff 100644 --- a/dbm-services/mysql/db-simulation/app/config/config.go +++ b/dbm-services/mysql/db-simulation/app/config/config.go @@ -1,3 +1,13 @@ +/* + * TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. + * Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. + * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at https://opensource.org/licenses/MIT + * 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 config TODO package config @@ -15,18 +25,20 @@ var GAppConfig = AppConfig{} // AppConfig TODO type AppConfig struct { - BkRepo BkRepoConfig `yaml:"bkrepo"` - Image Images - ListenAddr string `yaml:"listenAddr"` - RulePath string `yaml:"rulePath"` - SpiderRulePath string `yaml:"spiderRulePath"` - Bcs BcsConfig `yaml:"bcs"` - DbConf DbConfig `yaml:"dbconf"` - MirrorsAddress []ImgConfig `yaml:"mirrorsAddress"` - Debug bool `yaml:"debug"` - LoadRuleFromdb bool `yaml:"loadRuleFromdb"` - MySQLPodResource MySQLPodResource `yaml:"mysqlPodResource"` - TdbctlPodResource TdbctlPodResource `yaml:"tdbctlPodResource"` + BkRepo BkRepoConfig `yaml:"bkrepo"` + Image Images + ListenAddr string `yaml:"listenAddr"` + RulePath string `yaml:"rulePath"` + SpiderRulePath string `yaml:"spiderRulePath"` + Bcs BcsConfig `yaml:"bcs"` + DbConf DbConfig `yaml:"dbconf"` + MirrorsAddress []ImgConfig `yaml:"mirrorsAddress"` + Debug bool `yaml:"debug"` + LoadRuleFromdb bool `yaml:"loadRuleFromdb"` + MySQLPodResource MySQLPodResource `yaml:"mysqlPodResource"` + TdbctlPodResource TdbctlPodResource `yaml:"tdbctlPodResource"` + SimulationNodeLables map[string]string `yaml:"simulationNodeLables"` + SimulationtaintLables map[string]string `yaml:"simulationtaintLables"` } // BkRepoConfig TODO @@ -189,12 +201,12 @@ func init() { logger.Info("app config %v", GAppConfig) } -// IsEmptyMySQLPodResourceConfig TODO +// IsEmptyMySQLPodResourceConfig determine whether the pod resource limit configuration is empty func IsEmptyMySQLPodResourceConfig() bool { return GAppConfig.MySQLPodResource == MySQLPodResource{} } -// IsEmptyTdbctlPodResourceConfig TODO +// IsEmptyTdbctlPodResourceConfig determine whether the pod resource limit configuration is empty func IsEmptyTdbctlPodResourceConfig() bool { return GAppConfig.TdbctlPodResource == TdbctlPodResource{} } diff --git a/dbm-services/mysql/db-simulation/app/service/kubernets.go b/dbm-services/mysql/db-simulation/app/service/kubernets.go index 9febb9138d..3bc42925dd 100644 --- a/dbm-services/mysql/db-simulation/app/service/kubernets.go +++ b/dbm-services/mysql/db-simulation/app/service/kubernets.go @@ -131,6 +131,8 @@ func (k *DbPodSets) CreateClusterPod() (err error) { Labels: k.BaseInfo.Lables, }, Spec: v1.PodSpec{ + NodeSelector: config.GAppConfig.SimulationNodeLables, + Tolerations: k.getToleration(), Containers: []v1.Container{ { Name: "backend", @@ -219,7 +221,7 @@ func (k *DbPodSets) CreateClusterPod() (err error) { return nil } -// createpod TODO +// createpod create pod func (k *DbPodSets) createpod(pod *v1.Pod, probePort int) (err error) { podc, err := k.K8S.Cli.CoreV1().Pods(k.K8S.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{}) if err != nil { @@ -275,6 +277,18 @@ func (k *DbPodSets) createpod(pod *v1.Pod, probePort int) (err error) { return err } +// getToleration special node +func (k *DbPodSets) getToleration() []v1.Toleration { + ts := []v1.Toleration{} + for key, _ := range config.GAppConfig.SimulationNodeLables { + ts = append(ts, v1.Toleration{ + Key: key, + Operator: v1.TolerationOpExists, + }) + } + return ts +} + func (k *DbPodSets) getResourceLimit() v1.ResourceRequirements { if !config.IsEmptyMySQLPodResourceConfig() { return v1.ResourceRequirements{ @@ -320,6 +334,8 @@ func (k *DbPodSets) CreateMySQLPod() (err error) { Labels: k.BaseInfo.Lables, }, Spec: v1.PodSpec{ + NodeSelector: config.GAppConfig.SimulationNodeLables, + Tolerations: k.getToleration(), Containers: []v1.Container{{ Resources: k.getResourceLimit(), Name: app.MySQL, diff --git a/dbm-services/mysql/db-simulation/app/syntax/syntax.go b/dbm-services/mysql/db-simulation/app/syntax/syntax.go index 6f0f6b49f9..58ff02ebde 100644 --- a/dbm-services/mysql/db-simulation/app/syntax/syntax.go +++ b/dbm-services/mysql/db-simulation/app/syntax/syntax.go @@ -540,12 +540,16 @@ func (tf *TmysqlParse) AnalyzeOne(inputfileName, mysqlVersion, dbtype string) (e // 判断是否有语法错误 if res.ErrorCode != 0 { + errMsg := res.ErrorMsg vl := strings.Split(mysqlVersion, ".") + if len(vl) >= 2 { + errMsg = fmt.Sprintf("[%s]: %s", fmt.Sprintf("MySQL-%s.%s", vl[0], vl[1]), res.ErrorMsg) + } syntaxFailInfos = append(syntaxFailInfos, FailedInfo{ Line: int64(res.QueryId), Sqltext: res.QueryString, ErrorCode: int64(res.ErrorCode), - ErrorMsg: fmt.Sprintf("[%s]: %s", fmt.Sprintf("MySQL-%s.%s", vl[0], vl[1]), res.ErrorMsg), + ErrorMsg: errMsg, }) continue } diff --git a/helm-charts/bk-dbm/templates/configmaps/dbsimulation-configmap.yaml b/helm-charts/bk-dbm/templates/configmaps/dbsimulation-configmap.yaml index e91e1d4f5e..477bcab5b6 100644 --- a/helm-charts/bk-dbm/templates/configmaps/dbsimulation-configmap.yaml +++ b/helm-charts/bk-dbm/templates/configmaps/dbsimulation-configmap.yaml @@ -14,6 +14,15 @@ data: listenAddr: "0.0.0.0:80" rulePath: "rule.yaml" spiderRulePath: "spider_rule.yaml" + + {{- if index .Values "db-simulation" "simulationNodeLables" }} + simulationNodeLables: "{{ index .Values "db-simulation" "simulationNodeLables" }}" + {{- end }} + + {{- if index .Values "db-simulation" "simulationtaintLables" }} + simulationtaintLables:: "{{ index .Values "db-simulation" "simulationtaintLables" }}" + {{- end }} + bkrepo: project: "{{ .Values.bk.bkRepoProject }}" publicBucket: "{{ .Values.bk.bkRepoPublicBucket }}" diff --git a/helm-charts/bk-dbm/values.yaml b/helm-charts/bk-dbm/values.yaml index 114e81020f..bbf0c3dbe7 100644 --- a/helm-charts/bk-dbm/values.yaml +++ b/helm-charts/bk-dbm/values.yaml @@ -299,6 +299,10 @@ db-simulation: TRACE_TYPE: grpc TRACE_TOKEN: "" TRACE_DATA_ID: "" + # 模拟执行使用专用Node + # 需要迁移给专用节点打标签和污点 + simulationNodeLables: { bkdbm/simulation: "high-performance" } + simulationtaintLables: { bkdbm/simulation: "high-performance" } # 配置模拟执行 pod 的资源限额 # tdbctlPodResource: # limits: