mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
Merge branch 'third-component' of https://github.com/glyasai/rainbond into third-component
This commit is contained in:
commit
735634068b
@ -328,10 +328,10 @@ func (p *PluginAction) buildPlugin(b *api_model.BuildPluginStruct, plugin *dbmod
|
||||
Info: b.Body.Info,
|
||||
Status: "building",
|
||||
}
|
||||
if b.Body.PluginCPU == 0 {
|
||||
if b.Body.PluginCPU < 0 {
|
||||
pbv.ContainerCPU = 125
|
||||
}
|
||||
if b.Body.PluginMemory == 0 {
|
||||
if b.Body.PluginMemory < 0 {
|
||||
pbv.ContainerMemory = 50
|
||||
}
|
||||
if err := db.GetManager().TenantPluginBuildVersionDao().AddModel(pbv); err != nil {
|
||||
|
@ -154,14 +154,22 @@ func (s *ServiceAction) SetTenantServicePluginRelation(tenantID, serviceID strin
|
||||
tx.Rollback()
|
||||
return nil, util.CreateAPIHandleErrorFromDBError("set service plugin env error ", err)
|
||||
}
|
||||
tsprCPU := pluginversion.ContainerCPU
|
||||
tsprMemory := pluginversion.ContainerMemory
|
||||
if pss.Body.PluginCPU >= 0 {
|
||||
tsprCPU = pss.Body.PluginCPU
|
||||
}
|
||||
if pss.Body.PluginMemory >= 0 {
|
||||
tsprMemory = pss.Body.PluginMemory
|
||||
}
|
||||
relation := &dbmodel.TenantServicePluginRelation{
|
||||
VersionID: pss.Body.VersionID,
|
||||
ServiceID: serviceID,
|
||||
PluginID: pss.Body.PluginID,
|
||||
Switch: pss.Body.Switch,
|
||||
PluginModel: plugin.PluginModel,
|
||||
ContainerCPU: pluginversion.ContainerCPU,
|
||||
ContainerMemory: pluginversion.ContainerMemory,
|
||||
ContainerCPU: tsprCPU,
|
||||
ContainerMemory: tsprMemory,
|
||||
}
|
||||
if err := db.GetManager().TenantServicePluginRelationDaoTransactions(tx).AddModel(relation); err != nil {
|
||||
tx.Rollback()
|
||||
@ -182,10 +190,10 @@ func (s *ServiceAction) UpdateTenantServicePluginRelation(serviceID string, pss
|
||||
}
|
||||
relation.VersionID = pss.Body.VersionID
|
||||
relation.Switch = pss.Body.Switch
|
||||
if pss.Body.PluginCPU != 0 {
|
||||
if pss.Body.PluginCPU >= 0 {
|
||||
relation.ContainerCPU = pss.Body.PluginCPU
|
||||
}
|
||||
if pss.Body.PluginMemory != 0 {
|
||||
if pss.Body.PluginMemory >= 0 {
|
||||
relation.ContainerMemory = pss.Body.PluginMemory
|
||||
}
|
||||
err = db.GetManager().TenantServicePluginRelationDao().UpdateModel(relation)
|
||||
|
@ -89,9 +89,9 @@ type TenantPluginBuildVersion struct {
|
||||
Info string `gorm:"column:info" json:"info"`
|
||||
Status string `gorm:"column:status;size:24" json:"status"`
|
||||
// container default cpu
|
||||
ContainerCPU int `gorm:"column:container_cpu;default:125" json:"container_cpu"`
|
||||
ContainerCPU int `gorm:"column:container_cpu;default:0" json:"container_cpu"`
|
||||
// container default memory
|
||||
ContainerMemory int `gorm:"column:container_memory;default:64" json:"container_memory"`
|
||||
ContainerMemory int `gorm:"column:container_memory;default:0" json:"container_memory"`
|
||||
// container args
|
||||
ContainerCMD string `gorm:"column:container_cmd;size:2048" json:"container_cmd"`
|
||||
}
|
||||
@ -155,9 +155,9 @@ type TenantServicePluginRelation struct {
|
||||
ServiceID string `gorm:"column:service_id;size:32" json:"service_id"`
|
||||
PluginModel string `gorm:"column:plugin_model;size:24" json:"plugin_model"`
|
||||
// container default cpu v3.5.1 add
|
||||
ContainerCPU int `gorm:"column:container_cpu;default:125" json:"container_cpu"`
|
||||
ContainerCPU int `gorm:"column:container_cpu;default:0" json:"container_cpu"`
|
||||
// container default memory v3.5.1 add
|
||||
ContainerMemory int `gorm:"column:container_memory;default:64" json:"container_memory"`
|
||||
ContainerMemory int `gorm:"column:container_memory;default:0" json:"container_memory"`
|
||||
Switch bool `gorm:"column:switch;default:0" json:"switch"`
|
||||
}
|
||||
|
||||
|
@ -165,9 +165,11 @@ type TenantServices struct {
|
||||
// 服务描述
|
||||
Comment string `gorm:"column:comment" json:"comment"`
|
||||
// 容器CPU权重
|
||||
ContainerCPU int `gorm:"column:container_cpu;default:500" json:"container_cpu"`
|
||||
// default is 0, This means that CPU resources are not limited
|
||||
ContainerCPU int `gorm:"column:container_cpu;default:0" json:"container_cpu"`
|
||||
// 容器最大内存
|
||||
ContainerMemory int `gorm:"column:container_memory;default:128" json:"container_memory"`
|
||||
// default is 0, This means that Memory resources are not limited
|
||||
ContainerMemory int `gorm:"column:container_memory;default:0" json:"container_memory"`
|
||||
// container GPU, The amount of video memory applied for GPU. The unit is MiB
|
||||
// default is 0, That means no GPU is required
|
||||
ContainerGPU int `gorm:"column:container_gpu;default:0" json:"container_gpu"`
|
||||
|
@ -440,7 +440,7 @@ func createPluginEnvs(pluginID, tenantID, serviceAlias string, mainEnvs []v1.Env
|
||||
}
|
||||
|
||||
func createPluginResources(memory int, cpu int) v1.ResourceRequirements {
|
||||
return createResourcesByDefaultCPU(memory, int64(cpu), int64(cpu))
|
||||
return createResourcesBySetting(memory, int64(cpu), int64(cpu), 0)
|
||||
}
|
||||
|
||||
func createTCPUDPMeshRecources(as *typesv1.AppService) v1.ResourceRequirements {
|
||||
@ -458,12 +458,12 @@ func createTCPUDPMeshRecources(as *typesv1.AppService) v1.ResourceRequirements {
|
||||
memory = requestint
|
||||
}
|
||||
}
|
||||
return createResourcesByDefaultCPU(memory, cpu, func() int64 {
|
||||
return createResourcesBySetting(memory, cpu, func() int64 {
|
||||
if cpu < 120 {
|
||||
return 120
|
||||
}
|
||||
return cpu
|
||||
}())
|
||||
}(), 0)
|
||||
}
|
||||
|
||||
func xdsHostIPEnv(xdsHost string) corev1.EnvVar {
|
||||
|
@ -19,39 +19,34 @@
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
//Allocate the CPU at the ratio of 4g memory to 1 core CPU
|
||||
func createResourcesByDefaultCPU(memory int, setCPURequest, setCPULimit int64) corev1.ResourceRequirements {
|
||||
var cpuRequest, cpuLimit int64
|
||||
base := int64(memory) / 128
|
||||
if base <= 0 {
|
||||
base = 1
|
||||
}
|
||||
if memory < 512 {
|
||||
cpuRequest, cpuLimit = base*30, base*80
|
||||
} else if memory <= 1024 {
|
||||
cpuRequest, cpuLimit = base*30, base*160
|
||||
} else {
|
||||
cpuRequest, cpuLimit = base*30, ((int64(memory)-1024)/1024*500 + 1280)
|
||||
func createResourcesBySetting(memory int, setCPURequest, setCPULimit, setGPULimit int64) corev1.ResourceRequirements {
|
||||
limits := corev1.ResourceList{}
|
||||
request := corev1.ResourceList{}
|
||||
|
||||
if memory > 0 {
|
||||
limits[corev1.ResourceMemory] = *resource.NewQuantity(int64(memory*1024*1024), resource.BinarySI)
|
||||
}
|
||||
if setCPULimit > 0 {
|
||||
cpuLimit = setCPULimit
|
||||
limits[corev1.ResourceCPU] = *resource.NewMilliQuantity(setCPULimit, resource.DecimalSI)
|
||||
}
|
||||
if setGPULimit > 0 {
|
||||
gpuLimit, err := resource.ParseQuantity(fmt.Sprintf("%d", setGPULimit))
|
||||
if err != nil {
|
||||
logrus.Errorf("gpu request is invalid")
|
||||
} else {
|
||||
limits[getGPULableKey()] = gpuLimit
|
||||
}
|
||||
}
|
||||
|
||||
if setCPURequest > 0 {
|
||||
cpuRequest = setCPURequest
|
||||
request[corev1.ResourceCPU] = *resource.NewMilliQuantity(setCPURequest, resource.DecimalSI)
|
||||
}
|
||||
|
||||
limits := corev1.ResourceList{}
|
||||
limits[corev1.ResourceCPU] = *resource.NewMilliQuantity(cpuLimit, resource.DecimalSI)
|
||||
limits[corev1.ResourceMemory] = *resource.NewQuantity(int64(memory*1024*1024), resource.BinarySI)
|
||||
|
||||
request := corev1.ResourceList{}
|
||||
request[corev1.ResourceCPU] = *resource.NewMilliQuantity(cpuRequest, resource.DecimalSI)
|
||||
request[corev1.ResourceMemory] = *resource.NewQuantity(int64(memory*1024*1024), resource.BinarySI)
|
||||
|
||||
return corev1.ResourceRequirements{
|
||||
Limits: limits,
|
||||
Requests: request,
|
||||
|
@ -38,7 +38,6 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/sirupsen/logrus"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
@ -498,16 +497,11 @@ func createResources(as *v1.AppService) corev1.ResourceRequirements {
|
||||
cpuRequest = int64(requestint)
|
||||
}
|
||||
}
|
||||
rr := createResourcesByDefaultCPU(as.ContainerMemory, cpuRequest, cpuLimit)
|
||||
// support set gpu, support application of single GPU video memory.
|
||||
if as.ContainerGPU > 0 {
|
||||
gpuLimit, err := resource.ParseQuantity(fmt.Sprintf("%d", as.ContainerGPU))
|
||||
if err != nil {
|
||||
logrus.Errorf("gpu request is invalid")
|
||||
} else {
|
||||
rr.Limits[getGPULableKey()] = gpuLimit
|
||||
}
|
||||
if as.ContainerCPU > 0 && cpuRequest == 0 && cpuLimit == 0{
|
||||
cpuLimit = int64(as.ContainerCPU)
|
||||
cpuRequest = int64(as.ContainerCPU)
|
||||
}
|
||||
rr := createResourcesBySetting(as.ContainerMemory, cpuRequest, cpuLimit, int64(as.ContainerGPU))
|
||||
return rr
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user