From 1b4da7a1d4e40efdd0ce5baaff5ed179dac5a452 Mon Sep 17 00:00:00 2001 From: ymakedaq <996156275@qq.com> Date: Tue, 28 Nov 2023 20:29:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(dbm-services):=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=AF=AD=E4=B9=89=E6=A3=80=E6=9F=A5pod=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E9=99=90=E5=88=B6=20close=20#2179?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add config fix stage save --- .../mysql/db-simulation/app/config/config.go | 51 +++++++++++++++---- .../db-simulation/app/service/kubernets.go | 39 +++++++++++++- .../bk-dbm/charts/db-simulation/Chart.yaml | 2 +- .../templates/dbsimulation-configmap.yaml | 15 ++++++ 4 files changed, 95 insertions(+), 12 deletions(-) diff --git a/dbm-services/mysql/db-simulation/app/config/config.go b/dbm-services/mysql/db-simulation/app/config/config.go index c0a9c1fd87..05e08c535f 100644 --- a/dbm-services/mysql/db-simulation/app/config/config.go +++ b/dbm-services/mysql/db-simulation/app/config/config.go @@ -15,16 +15,18 @@ 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"` + 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"` } // BkRepoConfig TODO @@ -63,6 +65,24 @@ type DbConfig struct { Port int `yaml:"port"` } +// MySQLPodResource TODO +type MySQLPodResource struct { + Limits PodResource `yaml:"limits"` + Requests PodResource `yaml:"requests"` +} + +// TdbctlPodResource TODO +type TdbctlPodResource struct { + Limits PodResource `yaml:"limits"` + Requests PodResource `yaml:"requests"` +} + +// PodResource TODO +type PodResource struct { + Cpu string `yaml:"cpu"` + Mem string `yaml:"mem"` +} + // ImgConfig TODO type ImgConfig struct { Version string `yaml:"version"` @@ -164,6 +184,17 @@ func init() { } } logger.Info("app config %v", GAppConfig) + logger.Info("pod resource limit config %v", GAppConfig.MySQLPodResource) +} + +// IsEmptyMySQLPodResourceConfig TODO +func IsEmptyMySQLPodResourceConfig() bool { + return GAppConfig.MySQLPodResource == MySQLPodResource{} +} + +// IsEmptyTdbctlPodResourceConfig TODO +func IsEmptyTdbctlPodResourceConfig() bool { + return GAppConfig.TdbctlPodResource == TdbctlPodResource{} } // loadConfig 加载配置文件 diff --git a/dbm-services/mysql/db-simulation/app/service/kubernets.go b/dbm-services/mysql/db-simulation/app/service/kubernets.go index 39d58b218a..fd1e0f873a 100644 --- a/dbm-services/mysql/db-simulation/app/service/kubernets.go +++ b/dbm-services/mysql/db-simulation/app/service/kubernets.go @@ -30,6 +30,7 @@ import ( "github.com/pkg/errors" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" @@ -136,6 +137,7 @@ func (k *DbPodSets) CreateClusterPod() (err error) { Name: "MYSQL_ROOT_PASSWORD", Value: k.BaseInfo.RootPwd, }}, + Resources: k.getResourceLimit(), ImagePullPolicy: v1.PullIfNotPresent, Image: k.DbImage, Args: []string{"mysqld", "--defaults-file=/etc/my.cnf", "--port=20000", fmt.Sprintf("--character-set-server=%s", @@ -156,6 +158,7 @@ func (k *DbPodSets) CreateClusterPod() (err error) { Name: "MYSQL_ROOT_PASSWORD", Value: k.BaseInfo.RootPwd, }}, + Resources: k.getResourceLimit(), ImagePullPolicy: v1.PullIfNotPresent, Image: k.SpiderImage, Args: []string{"mysqld", "--defaults-file=/etc/my.cnf", "--port=25000", fmt.Sprintf("--character-set-server=%s", @@ -177,6 +180,7 @@ func (k *DbPodSets) CreateClusterPod() (err error) { Name: "MYSQL_ROOT_PASSWORD", Value: k.BaseInfo.RootPwd, }}, + Resources: k.gettdbctlResourceLimit(), ImagePullPolicy: v1.PullIfNotPresent, Image: k.TdbCtlImage, Args: []string{"mysqld", "--defaults-file=/etc/my.cnf", "--port=26000", "--tc-admin=1", @@ -267,6 +271,38 @@ func (k *DbPodSets) createpod(pod *v1.Pod, probePort int) (err error) { return err } +func (k *DbPodSets) getResourceLimit() v1.ResourceRequirements { + if !config.IsEmptyMySQLPodResourceConfig() { + return v1.ResourceRequirements{ + Limits: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse(config.GAppConfig.MySQLPodResource.Limits.Cpu), + v1.ResourceMemory: resource.MustParse(config.GAppConfig.MySQLPodResource.Limits.Mem), + }, + Requests: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse(config.GAppConfig.MySQLPodResource.Requests.Cpu), + v1.ResourceMemory: resource.MustParse(config.GAppConfig.MySQLPodResource.Requests.Mem), + }, + } + } + return v1.ResourceRequirements{} +} + +func (k *DbPodSets) gettdbctlResourceLimit() v1.ResourceRequirements { + if !config.IsEmptyTdbctlPodResourceConfig() { + return v1.ResourceRequirements{ + Limits: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse(config.GAppConfig.TdbctlPodResource.Limits.Cpu), + v1.ResourceMemory: resource.MustParse(config.GAppConfig.TdbctlPodResource.Limits.Mem), + }, + Requests: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse(config.GAppConfig.TdbctlPodResource.Requests.Cpu), + v1.ResourceMemory: resource.MustParse(config.GAppConfig.TdbctlPodResource.Requests.Mem), + }, + } + } + return v1.ResourceRequirements{} +} + // CreateMySQLPod TODO func (k *DbPodSets) CreateMySQLPod() (err error) { c := &v1.Pod{ @@ -281,7 +317,8 @@ func (k *DbPodSets) CreateMySQLPod() (err error) { }, Spec: v1.PodSpec{ Containers: []v1.Container{{ - Name: app.MySQL, + Resources: k.getResourceLimit(), + Name: app.MySQL, Env: []v1.EnvVar{{ Name: "MYSQL_ROOT_PASSWORD", Value: k.BaseInfo.RootPwd, diff --git a/helm-charts/bk-dbm/charts/db-simulation/Chart.yaml b/helm-charts/bk-dbm/charts/db-simulation/Chart.yaml index 16b8ab9d7b..36e4db1216 100644 --- a/helm-charts/bk-dbm/charts/db-simulation/Chart.yaml +++ b/helm-charts/bk-dbm/charts/db-simulation/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -appVersion: 0.0.1-alpha.40 +appVersion: 0.0.1-alpha.41 description: A Helm chart for Kubernetes name: db-simulation type: application diff --git a/helm-charts/bk-dbm/templates/dbsimulation-configmap.yaml b/helm-charts/bk-dbm/templates/dbsimulation-configmap.yaml index e2216def4f..d4b50fe298 100644 --- a/helm-charts/bk-dbm/templates/dbsimulation-configmap.yaml +++ b/helm-charts/bk-dbm/templates/dbsimulation-configmap.yaml @@ -44,3 +44,18 @@ data: host: "{{ $dbsimulationDB.host }}" port: "{{ $dbsimulationDB.port }}" debug: false + tdbctlPodResource: + limits: + cpu: "2" + mem: "4Gi" + requests: + cpu: "4" + mem: "8Gi" + mysqlPodResource: + limits: + cpu: "4" + mem: "8Gi" + requests: + cpu: "8" + mem: "16Gi" +