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

fix(computeresource/tasklevel): Fixed a bug where abnormal calculatio… #8399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions pkg/internal/computeresources/tasklevel/tasklevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func computeAverageRequests(requests corev1.ResourceList, steps int) corev1.Reso
}
averageRequests := corev1.ResourceList{}
for k, v := range requests {
if k == corev1.ResourceMemory || k == corev1.ResourceEphemeralStorage {
averageRequests[k] = *resource.NewQuantity(v.Value()/int64(steps), requests[k].Format)
continue
}
averageRequests[k] = *resource.NewMilliQuantity(v.MilliValue()/int64(steps), requests[k].Format)
}
return averageRequests
Expand Down
70 changes: 56 additions & 14 deletions pkg/internal/computeresources/tasklevel/tasklevel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ func TestApplyTaskLevelResourceRequirements(t *testing.T) {
Command: []string{"cmd"},
}},
ComputeResources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("2")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("2Mi"),
},
},
expectedComputeResources: []corev1.ResourceRequirements{{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Mi"),
},
}, {
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("1Mi"),
},
}},
}, {
desc: "only with limits",
Expand All @@ -65,14 +74,29 @@ func TestApplyTaskLevelResourceRequirements(t *testing.T) {
Command: []string{"cmd"},
}},
ComputeResources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("256Mi"),
},
},
expectedComputeResources: []corev1.ResourceRequirements{{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("250m")},
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("250m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("256Mi"),
},
}, {
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("250m")},
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("250m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("256Mi"),
},
}},
}, {
desc: "both with requests and limits",
Expand All @@ -86,15 +110,33 @@ func TestApplyTaskLevelResourceRequirements(t *testing.T) {
Command: []string{"cmd"},
}},
ComputeResources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1")},
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("2")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("4Mi"),
},
},
expectedComputeResources: []corev1.ResourceRequirements{{
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("2")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("1Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("4Mi"),
},
}, {
Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("500m")},
Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("2")},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("1Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("4Mi"),
},
}},
}, {
desc: "steps with compute resources are overridden by task-level compute resources",
Expand Down