Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherrypick #3569 #3574

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -762,42 +762,20 @@ func getResourceRequirements(resReq setting.Request, resReqSpec setting.RequestS
// cpu Request:Limit=1:4
// memory default Request:Limit=1:4 ; if memoryLimit>= 8Gi,Request:Limit=1:8
func generateResourceRequirements(req setting.Request, reqSpec setting.RequestSpec) corev1.ResourceRequirements {

if req != setting.DefineRequest {
return corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(strconv.Itoa(reqSpec.CpuLimit) + setting.CpuUintM),
corev1.ResourceMemory: resource.MustParse(strconv.Itoa(reqSpec.MemoryLimit) + setting.MemoryUintMi),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(strconv.Itoa(reqSpec.CpuReq) + setting.CpuUintM),
corev1.ResourceMemory: resource.MustParse(strconv.Itoa(reqSpec.MemoryReq) + setting.MemoryUintMi),
},
}
}

limits := corev1.ResourceList{}
requests := corev1.ResourceList{}

if reqSpec.CpuLimit > 0 {
cpuReqInt := reqSpec.CpuLimit / 4
if cpuReqInt < 1 {
cpuReqInt = 1
}
if reqSpec.CpuLimit != 0 {
limits[corev1.ResourceCPU] = resource.MustParse(strconv.Itoa(reqSpec.CpuLimit) + setting.CpuUintM)
requests[corev1.ResourceCPU] = resource.MustParse(strconv.Itoa(cpuReqInt) + setting.CpuUintM)
}

if reqSpec.MemoryLimit > 0 {
memoryReqInt := reqSpec.MemoryLimit / 4
if memoryReqInt >= 2*1024 {
memoryReqInt = memoryReqInt / 2
}
if memoryReqInt < 1 {
memoryReqInt = 1
}
if reqSpec.CpuReq != 0 {
requests[corev1.ResourceCPU] = resource.MustParse(strconv.Itoa(reqSpec.CpuReq) + setting.CpuUintM)
}
if reqSpec.MemoryReq != 0 {
requests[corev1.ResourceMemory] = resource.MustParse(strconv.Itoa(reqSpec.MemoryReq) + setting.MemoryUintMi)
}
if reqSpec.MemoryLimit != 0 {
limits[corev1.ResourceMemory] = resource.MustParse(strconv.Itoa(reqSpec.MemoryLimit) + setting.MemoryUintMi)
requests[corev1.ResourceMemory] = resource.MustParse(strconv.Itoa(memoryReqInt) + setting.MemoryUintMi)
}

// add gpu limit
Expand Down
4 changes: 2 additions & 2 deletions pkg/setting/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (
type RequestSpec struct {
CpuLimit int `bson:"cpu_limit" json:"cpu_limit" yaml:"cpu_limit"`
MemoryLimit int `bson:"memory_limit" json:"memory_limit" yaml:"memory_limit"`
CpuReq int `bson:"cpu_req,omitempty" json:"cpu_req,omitempty" yaml:"cpu_req,omitempty"`
MemoryReq int `bson:"memory_req,omitempty" json:"memory_req,omitempty" yaml:"memory_req,omitempty"`
CpuReq int `bson:"cpu_req" json:"cpu_req" yaml:"cpu_req"`
MemoryReq int `bson:"memory_req" json:"memory_req" yaml:"memory_req"`
// gpu request, eg: "nvidia.com/gpu: 1"
GpuLimit string `bson:"gpu_limit" json:"gpu_limit" yaml:"gpu_limit"`
}
Expand Down
Loading