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 incorrect snapshot usage when lendingLimit enabled #1770

Merged
merged 1 commit into from Mar 12, 2024

Conversation

kerthcet
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

cc @B1F030 I reproduced the bug with a preemption test, PTAL.

Which issue(s) this PR fixes:

Fixes #1385 (comment)

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix incorrect quota management when lendingLimit enabled in preemption

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Categorizes issue or PR as related to a bug. labels Feb 26, 2024
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 26, 2024
Copy link

netlify bot commented Feb 26, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit f6369a1
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/65ef5365bcf59c00087f7817

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 27, 2024
@alculquicondor
Copy link
Contributor

/cc

pkg/scheduler/preemption/preemption_test.go Show resolved Hide resolved
@@ -1043,6 +1042,27 @@ func TestPreemption(t *testing.T) {
wantPreempted: sets.New("/lend1-low", "/lend2-low"),
enableLendingLimit: true,
},
"preempt from one ClusterQueue in cohort-lend": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"preempt from one ClusterQueue in cohort-lend": {
"cannot preempt from other ClusterQueue if past lending limit": {

Or another message that describes what the input and output is like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -43,18 +43,57 @@ func (s *Snapshot) RemoveWorkload(wl *workload.Info) {
delete(cq.Workloads, workload.Key(wl.Obj))
updateUsage(wl, cq.Usage, -1)
if cq.Cohort != nil {
updateUsage(wl, cq.Cohort.Usage, -1)
if features.Enabled(features.LendingLimit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have unit tests just for these functions. We should test for the transitions from "usage below guaranteed" and "usage above guaranteed" and the reverse, but also to the same states.
I'm not convinced the current implementation works.

However, maybe a simpler approach is:

  1. remove the existing "clusterqueue usage from the cohort"
  2. updateUsage(wl, cq.Usage, +-1)
  3. Add the new "clusterqueue usage from cohort"

Copy link
Member

@B1F030 B1F030 Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some tests that can prove the current implementation works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, maybe a simpler approach is:

+1, more readable to me. And I think the code is reuseable for Addworkload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

flv, flvExist := cq.Cohort.Usage[wlResFlv]
if flvExist && wlResExist {
if _, exists := flv[wlRes]; exists {
cohortUsage := cq.Usage[wlResFlv][wlRes] - cq.guaranteedQuota(wlResFlv, wlRes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cohortUsage := cq.Usage[wlResFlv][wlRes] - cq.guaranteedQuota(wlResFlv, wlRes)
nonGuaranteedUsage := cq.Usage[wlResFlv][wlRes] - cq.guaranteedQuota(wlResFlv, wlRes)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 28, 2024
for _, ps := range wl.TotalRequests {
for wlRes, wlResFlv := range ps.Flavors {
v, wlResExist := ps.Requests[wlRes]
// update cq.Cohort.Usage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment. Meaningless

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -43,18 +43,57 @@ func (s *Snapshot) RemoveWorkload(wl *workload.Info) {
delete(cq.Workloads, workload.Key(wl.Obj))
updateUsage(wl, cq.Usage, -1)
if cq.Cohort != nil {
updateUsage(wl, cq.Cohort.Usage, -1)
if features.Enabled(features.LendingLimit) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, maybe a simpler approach is:

+1, more readable to me. And I think the code is reuseable for Addworkload.

}(),
enableLendingLimit: true,
},
"remove lend-a-2": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz make the test name more readable, like the intention you want to test here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -1043,6 +1042,27 @@ func TestPreemption(t *testing.T) {
wantPreempted: sets.New("/lend1-low", "/lend2-low"),
enableLendingLimit: true,
},
"cannot preempt from other ClusterQueues if past lending limit": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"cannot preempt from other ClusterQueues if past lending limit": {
"cannot preempt from other ClusterQueues if exceeds requestable qutota including lending limit": {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

@kerthcet kerthcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General LGTM

@@ -43,18 +43,26 @@ func (s *Snapshot) RemoveWorkload(wl *workload.Info) {
delete(cq.Workloads, workload.Key(wl.Obj))
updateUsage(wl, cq.Usage, -1)
if cq.Cohort != nil {
updateUsage(wl, cq.Cohort.Usage, -1)
if features.Enabled(features.LendingLimit) {
updateCohortUsage(wl, cq, cq.Cohort.Usage, -1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass cq as parameters only?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

pkg/cache/snapshot_test.go Show resolved Hide resolved
remove []string
add []string
want Snapshot
enableLendingLimit bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of this field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@kerthcet kerthcet changed the title [WIP]Fix incorrect snapshot usage when lendingLimit enabled Fix incorrect snapshot usage when lendingLimit enabled Feb 28, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 28, 2024
@kerthcet
Copy link
Contributor Author

/assign @alculquicondor

add: []string{"/lend-a-1", "/lend-a-2", "/lend-a-3", "/lend-b-1"},
want: initialSnapshot,
},
"remove all with lending limit": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"remove all with lending limit": {
"remove all": {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

workloads := []kueue.Workload{
*utiltesting.MakeWorkload("lend-a-1", "").
Request(corev1.ResourceCPU, "1").
ReserveQuota(utiltesting.MakeAdmission("lend-a").Assignment(corev1.ResourceCPU, "default", "1000m").Obj()).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ReserveQuota(utiltesting.MakeAdmission("lend-a").Assignment(corev1.ResourceCPU, "default", "1000m").Obj()).
ReserveQuota(utiltesting.MakeAdmission("lend-a").Assignment(corev1.ResourceCPU, "default", "1").Obj()).

For readability. Do the same for the rest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
cmpOpts := append(snapCmpOpts,
cmpopts.IgnoreFields(ClusterQueue{}, "NamespaceSelector", "Preemption", "Status"),
cmpopts.IgnoreFields(Cohort{}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something looks off here. Not sure what this is ignoring. I think we should ignore ClusterQueues within Cohort to avoid recursion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ignoring the whole Cohort struct. In this test function, all cqs belong to a same cohort, so there will be no difference. I think it's ok not to change this. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we actually want to check that the Usage field matches what is set in tc.want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds resonable, modified.

@@ -1043,6 +1041,27 @@ func TestPreemption(t *testing.T) {
wantPreempted: sets.New("/lend1-low", "/lend2-low"),
enableLendingLimit: true,
},
"cannot preempt from other ClusterQueues if exceeds requestable qutota including lending limit": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"cannot preempt from other ClusterQueues if exceeds requestable qutota including lending limit": {
"cannot preempt from other ClusterQueues if exceeds requestable quota including lending limit": {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thx. Done.

*utiltesting.MakeWorkload("lend2-low", "").
Priority(-1).
Request(corev1.ResourceCPU, "10").
ReserveQuota(utiltesting.MakeAdmission("lend2").Assignment(corev1.ResourceCPU, "default", "10000m").Obj()).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ReserveQuota(utiltesting.MakeAdmission("lend2").Assignment(corev1.ResourceCPU, "default", "10000m").Obj()).
ReserveQuota(utiltesting.MakeAdmission("lend2").Assignment(corev1.ResourceCPU, "default", "10").Obj()).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Co-authored-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: B1F030 <b1fzhang@gmail.com>
@alculquicondor
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 83aaa484b027d52b380c0d645f2093f6ab5ea720

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, kerthcet

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2024
@alculquicondor
Copy link
Contributor

/cherry-pick release-0.6

@k8s-infra-cherrypick-robot

@alculquicondor: once the present PR merges, I will cherry-pick it on top of release-0.6 in a new PR and assign it to you.

In response to this:

/cherry-pick release-0.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot merged commit 604dc07 into kubernetes-sigs:main Mar 12, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.7 milestone Mar 12, 2024
@k8s-infra-cherrypick-robot

@alculquicondor: new pull request created: #1826

In response to this:

/cherry-pick release-0.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

vsoch pushed a commit to researchapps/kueue that referenced this pull request Apr 18, 2024
kubernetes-sigs#1770)

Signed-off-by: B1F030 <b1fzhang@gmail.com>
Co-authored-by: B1F030 <b1fzhang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants