Skip to content

Commit

Permalink
feat(dbm-services): 模拟执行的pod调度到指定节点 #4824
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Jun 11, 2024
1 parent 840692a commit b2a3c62
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
40 changes: 26 additions & 14 deletions dbm-services/mysql/db-simulation/app/config/config.go
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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{}
}
Expand Down
18 changes: 17 additions & 1 deletion dbm-services/mysql/db-simulation/app/service/kubernets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion dbm-services/mysql/db-simulation/app/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
4 changes: 4 additions & 0 deletions helm-charts/bk-dbm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b2a3c62

Please sign in to comment.