Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ichekrygin
Copy link
Contributor

@ichekrygin ichekrygin commented Sep 23, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR fixes bug when scaled-up workload stuck pending not triggering preemption.

Which issue(s) this PR fixes:

Fixes #6969

Special notes for your reviewer:

Does this PR introduce a user-facing change?

ElasticJobs: workloads correctly trigger workload preemption in response to a scale-up event.

…bsViaWorkloadSlices and PartialAdmission

These two features are not designed to work together.
While admission webhooks already prevent `PartialAdmission` from being combined with `ElasticJobsViaWorkloadSlices`, we add this safety check in the scheduler as well to guard against misconfiguration. This ensures that both features cannot be enabled at the same time, avoiding unexpected scheduling behavior.

Signed-off-by: Illya Chekrygin <[email protected]>
…estFor

Ensures that when a workload slice is replaced, its resource requests are properly reflected in `TotalRequestFor` during flavor assignment and subsequent preemption targets list generation.

Signed-off-by: Illya Chekrygin <[email protected]>
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Sep 23, 2025
Copy link

netlify bot commented Sep 23, 2025

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit e443d93
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-kueue/deploys/68d4212d0b3ba2000985aa8f

@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. labels Sep 23, 2025
@ichekrygin
Copy link
Contributor Author

/test pull-kueue-test-integration-baseline-main
/test pull-kueue-test-integration-extended-main

Copy link
Member

@tenzen-y tenzen-y left a comment

Choose a reason for hiding this comment

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

I didn't check all, but left a few comments

}
cfg = fwk.Init()
ctx, k8sClient = fwk.SetupClient(cfg)
gomega.Expect(utilfeature.DefaultMutableFeatureGate.SetFromMap(map[string]bool{string(features.ElasticJobsViaWorkloadSlices): true})).Should(gomega.Succeed())
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid enabling such Alpha feature at global level. We should set the FG only in the affected case.
You can learn HOW in

features.SetFeatureGateDuringTest(ginkgo.GinkgoTB(), features.MultiKueueBatchJobWithManagedBy, true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah... yes. Good catch! For some reason I thought I need "feature" activation at the manager level.
Reverted.

Comment on lines 178 to 185
if a.replaceWorkloadSlice != nil {
ps = *ps.ScaledTo(ps.Count - a.replaceWorkloadSlice.TotalRequests[i].Count)
} else {
aps := a.PodSets[i]
if aps.Count != ps.Count {
ps = *ps.ScaledTo(aps.Count)
}
}
Copy link
Contributor

@mimowo mimowo Sep 24, 2025

Choose a reason for hiding this comment

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

Instead of doing two independent branches could we just decrement the value we are scaling?

Something like:

newCount := a.PodSets[i].Count
if a.replaceWorkloadSlice != nil {
  newCount -= a.replaceWorkloadSlice.TotalRequests[i].Count
}
ps = *ps.ScaledTo(newCount)

wdyt?

util.ExpectObjectToBeDeleted(ctx, k8sClient, cq, true)
})

ginkgo.It("Should preempt on-create Workloads with lower priority when there is not enough quota", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this "It" introduce additional coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s updated (PTAL), with feature activation moved into the test-case scope.
This test is dedicated to validating that general workload preemption works — specifically, that an elastic workload can preempt another job outside of the scale-up context. In other words, it serves more as a sanity check.

Happy to remove it if we think it’s redundant.

Copy link
Contributor

@mimowo mimowo Sep 24, 2025

Choose a reason for hiding this comment

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

I see the motivation. OTOH we already have a test exercising priority based preemption (in the simple case) for ElasticJobs here:

highPriorityJob := testingjob.MakeJob("high", ns.Name).
SetAnnotation(workloadslicing.EnabledAnnotationKey, workloadslicing.EnabledAnnotationValue).
Queue(kueue.LocalQueueName(localQueue.Name)).
Request(corev1.ResourceCPU, "1000m").
Parallelism(3).
Completions(3).
WorkloadPriorityClass(highPriorityClass.Name).
Obj()

I know the pre-existing test is a bit more involving, but I'm unclear adding the new small test makes it easier to understand.

I would focus only on the issue at hand and drop the extra test. I would be happy to keep it if we haven't had the other preexisting test already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

}

if features.Enabled(features.PartialAdmission) && wl.CanBePartiallyAdmitted() {
if features.Enabled(features.PartialAdmission) && wl.CanBePartiallyAdmitted() && replaceableWorkloadSlice == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have some test for this? IIUC the new integration tests (or the reported issue) also show up with the "PartialAdmission" disabled? So, I think this code change may not be exercised by the integration tests

Copy link
Contributor

Choose a reason for hiding this comment

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

So, IIUC this code change is fixing a different issue. Also, I'm wondering if we shouldn't just disable PartialAdmission for ElasticJobs at the validation level.

Let me know if I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, IIUC this code change is fixing a different issue. Also, I'm wondering if we shouldn't just disable PartialAdmission for ElasticJobs at the validation level.

We already enforce that at the validation level. The purpose of this change is to add a sanity check, ensuring that PartialAdmission (PA) is never combined with ElasticJobs (EJ). It also serves as an explicit reminder at the scheduler level that PA is not compatible with EJ.

Please let me know if this addition is a "block", I am happy to revert this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's cleanup the code. We can rely on validation, this is the common practice in k8s, to avoid checking against invariants which are satisfied by validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mimowo
Copy link
Contributor

mimowo commented Sep 24, 2025

Thank you 👍
/lgtm
/approve
/cherry-pick release-0.13

@k8s-infra-cherrypick-robot
Copy link
Contributor

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

In response to this:

Thank you 👍
/lgtm
/approve
/cherry-pick release-0.13

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-sigs/prow repository.

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

LGTM label has been added.

Git tree hash: 52172b576dc766e81a53b27176d90af8834b2e91

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ichekrygin, mimowo

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 Sep 24, 2025
@k8s-ci-robot k8s-ci-robot merged commit 19ebce0 into kubernetes-sigs:main Sep 24, 2025
23 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.14 milestone Sep 24, 2025
@k8s-infra-cherrypick-robot
Copy link
Contributor

@mimowo: #6973 failed to apply on top of branch "release-0.13":

Applying: Scheduler: add safety check to ensure mutual exclusivity of ElasticJobsViaWorkloadSlices and PartialAdmission
Applying: Fix: account for replaced workload slice in assigned flavor TotalRequestFor
Using index info to reconstruct a base tree...
M	pkg/scheduler/flavorassigner/flavorassigner.go
M	pkg/scheduler/flavorassigner/flavorassigner_test.go
M	test/integration/singlecluster/scheduler/preemption_test.go
M	test/integration/singlecluster/scheduler/suite_test.go
Falling back to patching base and 3-way merge...
Auto-merging test/integration/singlecluster/scheduler/suite_test.go
CONFLICT (content): Merge conflict in test/integration/singlecluster/scheduler/suite_test.go
Auto-merging test/integration/singlecluster/scheduler/preemption_test.go
Auto-merging pkg/scheduler/flavorassigner/flavorassigner_test.go
Auto-merging pkg/scheduler/flavorassigner/flavorassigner.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0002 Fix: account for replaced workload slice in assigned flavor TotalRequestFor

In response to this:

Thank you 👍
/lgtm
/approve
/cherry-pick release-0.13

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-sigs/prow repository.

@ichekrygin ichekrygin deleted the wl-slice-preemption branch September 24, 2025 22:50
@mimowo
Copy link
Contributor

mimowo commented Sep 25, 2025

@ichekrygin can you maybe prepare the cherry-pick? The ./hack/cherry_pick_pull.sh script is pretty useful for that.

ichekrygin added a commit to ichekrygin/kueue that referenced this pull request Sep 25, 2025
…ubernetes-sigs#6973)

* Scheduler: add safety check to ensure mutual exclusivity of ElasticJobsViaWorkloadSlices and PartialAdmission

These two features are not designed to work together.
While admission webhooks already prevent `PartialAdmission` from being combined with `ElasticJobsViaWorkloadSlices`, we add this safety check in the scheduler as well to guard against misconfiguration. This ensures that both features cannot be enabled at the same time, avoiding unexpected scheduling behavior.

Signed-off-by: Illya Chekrygin <[email protected]>

* Fix: account for replaced workload slice in assigned flavor TotalRequestFor

Ensures that when a workload slice is replaced, its resource requests are properly reflected in `TotalRequestFor` during flavor assignment and subsequent preemption targets list generation.

Signed-off-by: Illya Chekrygin <[email protected]>

* Revert feature enablement at the suite level, replacing it with test-case scoped feature activation.

Signed-off-by: Illya Chekrygin <[email protected]>

* Update TotalRequestsFor calculation per PR feedback.

Signed-off-by: Illya Chekrygin <[email protected]>

* Revert change in scheduler removing check for ElasticWorkload.

Signed-off-by: Illya Chekrygin <[email protected]>

* Remove "redundant" integration test.

Signed-off-by: Illya Chekrygin <[email protected]>

---------

Signed-off-by: Illya Chekrygin <[email protected]>
(cherry picked from commit 19ebce0)
k8s-ci-robot pushed a commit that referenced this pull request Sep 25, 2025
…6973) (#7013)

* Scheduler: add safety check to ensure mutual exclusivity of ElasticJobsViaWorkloadSlices and PartialAdmission

These two features are not designed to work together.
While admission webhooks already prevent `PartialAdmission` from being combined with `ElasticJobsViaWorkloadSlices`, we add this safety check in the scheduler as well to guard against misconfiguration. This ensures that both features cannot be enabled at the same time, avoiding unexpected scheduling behavior.



* Fix: account for replaced workload slice in assigned flavor TotalRequestFor

Ensures that when a workload slice is replaced, its resource requests are properly reflected in `TotalRequestFor` during flavor assignment and subsequent preemption targets list generation.



* Revert feature enablement at the suite level, replacing it with test-case scoped feature activation.



* Update TotalRequestsFor calculation per PR feedback.



* Revert change in scheduler removing check for ElasticWorkload.



* Remove "redundant" integration test.



---------


(cherry picked from commit 19ebce0)

Signed-off-by: Illya Chekrygin <[email protected]>
@tenzen-y
Copy link
Member

/release-note-edit

ElasticJobs: workloads correctly trigger workload preemption in response to a scale-up event.

@mimowo mimowo mentioned this pull request Sep 30, 2025
36 tasks
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ElasticJobs] scale-up workload stuck pending: preemption not triggered.
5 participants