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

Add APIs for configuring fair sharing #2070

Merged
merged 10 commits into from May 8, 2024

Conversation

alculquicondor
Copy link
Contributor

@alculquicondor alculquicondor commented Apr 25, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

Add APIs for fair sharing:

  • In KueueConfiguration, a new FairSharing struct to enable the feature and configure strategies.
  • In ClusterQueueSpec, a new FairSharing struct containing the weight.

Which issue(s) this PR fixes:

Fixes #1714

Special notes for your reviewer:

At this point, I'm looking for feedback on the types and field documentation.

Does this PR introduce a user-facing change?

Add fair sharing when borrowing unused resources from other ClusterQueues in a cohort.

Fair sharing is based on DRF for usage above nominal quotas.
When fair sharing is enabled, Kueue prefers to admit workloads from ClusterQueues with the lowest share first.
Administrators can enable and configure fair sharing preemption using a combination of two policies: `LessThanOrEqualtoFinalShare`, `LessThanInitialShare`.

You can define a fair sharing `weight` for ClusterQueues. The weight determines how much of the unused resources each ClusterQueue can take in comparison to others.

@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/feature Categorizes issue or PR as related to a new feature. labels Apr 25, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 25, 2024
Copy link

netlify bot commented Apr 25, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 357b499
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/663ba16103576a0008c34782

@alculquicondor
Copy link
Contributor Author

cc @mwielgus @tenzen-y

apis/kueue/v1beta1/clusterqueue_types.go Show resolved Hide resolved
apis/config/v1beta1/configuration_types.go Outdated Show resolved Hide resolved
apis/config/v1beta1/configuration_types.go Outdated Show resolved Hide resolved
apis/config/v1beta1/configuration_types.go Outdated Show resolved Hide resolved
apis/config/v1beta1/configuration_types.go Outdated Show resolved Hide resolved
@alculquicondor alculquicondor force-pushed the fair-sharing-api branch 4 times, most recently from cdb3926 to 87453cf Compare April 26, 2024 18:57
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 left a comment for a nit.

pkg/config/validation.go Outdated Show resolved Hide resolved
@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 May 3, 2024
@alculquicondor alculquicondor changed the title WIP: Add APIs for configuring fair sharing Add APIs for configuring fair sharing May 3, 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 May 3, 2024
@alculquicondor alculquicondor force-pushed the fair-sharing-api branch 2 times, most recently from 9cb7292 to fc94535 Compare May 3, 2024 18:02
@alculquicondor
Copy link
Contributor Author

This is now ready for review 😄

/assign @tenzen-y @mwielgus

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.

Totally, lgtm
I left a few comments.
By the way, it seems that the fairSharing feature overlaps borrowWithinCohort at some points. So, in the v1 API, we might be able to consolidate both APIs into a single one or provide a comprehensive feature somehow.

pkg/cache/clusterqueue.go Outdated Show resolved Hide resolved
pkg/scheduler/preemption/preemption.go Outdated Show resolved Hide resolved
@alculquicondor
Copy link
Contributor Author

By the way, it seems that the fairSharing feature overlaps borrowWithinCohort at some points. So, in the v1 API, we might be able to consolidate both APIs into a single one or provide a comprehensive feature somehow.

Did you mean that borrowWithinCohort can be replaced by using weight: 0?

If so, I agree. I would like to completely remove borrowWithinCohort once we go to v1, unless we hear some opposing feedback.

@kerthcet
Copy link
Contributor

kerthcet commented May 6, 2024

borrowWithinCohort once we go to v1, unless we

But why, do we have similar capacity covered this?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2024
Change-Id: I74b24ba8715290753c0bd9b966a109b5b01078b4
Change-Id: If347eabdb17af643d46a1e4ad78b79e73c424011
Change-Id: I6938d83399c55fecf952a570e2e431ad4ab479b2
Change-Id: I8b49d21f0b0e7a7d2607d9589ba49a4a914cd2aa
Change-Id: I68ba0c546ce27d9e6565a30584aacd67fd318ede
Change-Id: I375166b8c7fdc300eeb43ede25fbcbe73298c7a2
Change-Id: I4d56c73f4a949fa5c2b2053fd83a7161553755b0
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 7, 2024
// This strategy doesn't depend on the share usage of the workload being preempted.
// As a result, the strategy chooses to preempt workloads with the lowest priority and
// newest start time first.
// The default strategy is ["LessThanOrEqualToFinalShare"].
Copy link
Contributor

Choose a reason for hiding this comment

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

As per offline discussions we consider the two combinations as most likely in use:

  1. [LessThanOrEqualToFinalShare, LessThanInitialShare] and
  2. [LessThanInitialShare]

So, I would suggest setting the default to one of the configurations.

I would vote for the [LessThanOrEqualToFinalShare, LessThanInitialShare] since it matches the KEP.

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 s[0] == config.LessThanInitialShare {
result[0] = lessThanInitialShare
// This rule is a superset of the other rule, no need to check other strategies.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we go for the "mathematical" approach, I would suggest to be precise, and don't make the assumption that Rule B is a superset of Rule A (since unlikely scenarios may happen).

allErrs = append(allErrs, field.Invalid(fsPreemptionStrategiesPath, fs.PreemptionStrategies, "Must be empty when fair sharing is disabled"))
}
strategies := sets.New[configapi.PreemptionStrategy]()
validStrategies := []configapi.PreemptionStrategy{configapi.LessThanInitialShare, configapi.LessThanOrEqualToFinalShare}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should either validate against non-supported configurations or support them. I'm leaning towards validation, because it will keep the code simpler. IIUC this is the only non-supported option for now: [LessThanInitialShare, LessThanOrEqualToFinalShare] .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed validation to have an explicit list of supported combinations.

@alculquicondor
Copy link
Contributor Author

borrowWithinCohort once we go to v1, unless we

But why, do we have similar capacity covered this?

Yes, the biggest motivation to have borrowWithinCohort was to allow certain ClusterQueues to always be preempted whenever some other CQ needs the resources.

And this can be easily achieved when enabling fair sharing, by setting the weight on these "preemptible" CQs to zero.

Change-Id: I6893b7854656601e80f157b60caea27e27dfe4ea
Change-Id: I6379c4304cfb45a08940d57a24b79c6b1564ccca
@alculquicondor
Copy link
Contributor Author

@tenzen-y anything to add?

@@ -50,3 +50,6 @@ integrations:
# - key: kubernetes.io/metadata.name
# operator: NotIn
# values: [ kube-system, kueue-system ]
# fairSharing:
# enable: true
# preemptionStrategies: [LessThanOrEqualToFinalShare]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe align this with the current default?

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

Comment on lines 211 to 213
if !fs.Enable && len(fs.PreemptionStrategies) != 0 {
allErrs = append(allErrs, field.Invalid(fsPreemptionStrategiesPath, fs.PreemptionStrategies, "Must be empty when fair sharing is disabled"))
}
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 need it? I guess it can be handy to keep th configuration when temporarily disabling the feature.
Similarly as for waitForPodsReady.

Copy link
Member

Choose a reason for hiding this comment

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

If there are no drawbacks (similar to additional computation, and potentially bugs in preemptor), I would prefer to apply the @mimowo proposal here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG. Done

@mimowo
Copy link
Contributor

mimowo commented May 8, 2024

I did another pass for fair sharing, lgtm, just the two nit-like comments

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.

LGTM
Thank you!

apis/config/v1beta1/configuration_types.go Show resolved Hide resolved
Comment on lines 211 to 213
if !fs.Enable && len(fs.PreemptionStrategies) != 0 {
allErrs = append(allErrs, field.Invalid(fsPreemptionStrategiesPath, fs.PreemptionStrategies, "Must be empty when fair sharing is disabled"))
}
Copy link
Member

Choose a reason for hiding this comment

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

If there are no drawbacks (similar to additional computation, and potentially bugs in preemptor), I would prefer to apply the @mimowo proposal here.

Change-Id: I1ec9229cb866d31ece5046741ac7686157639758
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.

Hugely LGTM!
The implementation of the FairSharing feature inspired by Dominant Resource Fairness was not a really easy journey! Awsome 🎉

/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 May 8, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 07fccade5bb30526c1bae6d4b147b6d21d43dcf8

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, tenzen-y

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:
  • OWNERS [alculquicondor,tenzen-y]

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 merged commit 54d1c01 into kubernetes-sigs:main May 8, 2024
15 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.7 milestone May 8, 2024
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/feature Categorizes issue or PR as related to a new feature. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for fair sharing of unused resources
6 participants