diff --git a/api/handler/plugin.go b/api/handler/plugin.go index 071c57115..5d13da170 100644 --- a/api/handler/plugin.go +++ b/api/handler/plugin.go @@ -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 { diff --git a/api/handler/service_plugin.go b/api/handler/service_plugin.go index 99981e84f..066d507e6 100644 --- a/api/handler/service_plugin.go +++ b/api/handler/service_plugin.go @@ -156,10 +156,10 @@ func (s *ServiceAction) SetTenantServicePluginRelation(tenantID, serviceID strin } tsprCPU := pluginversion.ContainerCPU tsprMemory := pluginversion.ContainerMemory - if pss.Body.PluginCPU != 0 { + if pss.Body.PluginCPU >= 0 { tsprCPU = pss.Body.PluginCPU } - if pss.Body.PluginMemory != 0 { + if pss.Body.PluginMemory >= 0 { tsprMemory = pss.Body.PluginMemory } relation := &dbmodel.TenantServicePluginRelation{ @@ -190,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) diff --git a/db/model/plugin.go b/db/model/plugin.go index 80be0b4c5..1008c2d91 100644 --- a/db/model/plugin.go +++ b/db/model/plugin.go @@ -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"` } diff --git a/db/model/tenant.go b/db/model/tenant.go index 66f13facf..31d29aa55 100644 --- a/db/model/tenant.go +++ b/db/model/tenant.go @@ -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"` diff --git a/worker/appm/conversion/resource.go b/worker/appm/conversion/resource.go index 4f9bc59ef..7b361ed33 100644 --- a/worker/appm/conversion/resource.go +++ b/worker/appm/conversion/resource.go @@ -30,17 +30,21 @@ func createResourcesByDefaultCPU(memory int, setCPURequest, setCPULimit int64) c if base <= 0 { base = 1 } - if memory < 512 { - cpuRequest, cpuLimit = base*30, base*80 - } else if memory <= 1024 { - cpuRequest, cpuLimit = base*30, base*160 + if memory > 0 { + 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 + } } else { - cpuRequest, cpuLimit = base*30, ((int64(memory)-1024)/1024*500 + 1280) + memory = 0 } - if setCPULimit > 0 { + if setCPULimit >= 0 { cpuLimit = setCPULimit } - if setCPURequest > 0 { + if setCPURequest >= 0 { cpuRequest = setCPURequest }