-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Support for resource quota on extended resources #57302
Support for resource quota on extended resources #57302
Conversation
/area hw-accelerators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks okay to me.
pkg/quota/evaluator/core/pods.go
Outdated
@@ -244,13 +245,13 @@ func podComputeUsageHelper(requests api.ResourceList, limits api.ResourceList) a | |||
result[api.ResourceLimitsEphemeralStorage] = limit | |||
} | |||
for resource, request := range requests { | |||
if quota.ContainsPrefix(requestedResourcePrefixes, resource) { | |||
if quota.ContainsPrefix(requestedResourcePrefixes, resource) || helper.IsExtendedResourceName(resource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This revision is kind of hijacking the hugepages logic for extended resources, although the call to maskResourceWithPrefix below is unnecessary. So I'd suggest we add two separate loops for extended resources with comments.
The current logic is unnecessarily coupling extended resources to hugepages. This is not good for future maintenance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, done.
@tengqm Not quite sure about your meaning by "it is NOT OKAY to have devices reused across all regular containers by default", I think we never plan to support that anywhere. Also I fail to see relationship between resourceQuota support and the restriction. |
@lichuqiang As a practice and for the sake of convenience of others, may i request you to please update the consolidated RMWG PR/issues excel sheet with this PR, if have not already. |
/sig node |
In the existing code even today, limits cannot be unequal to requests for the ER. If the containe spec mentions so, will fail at validation. |
Nope, maybe you should take another look at #56818, I think we didn't introduce the mechanism to reuse resources between regular containers :) |
Yep, thus, as @derekwaynecarr suggested: "we can only worry about quota on requests for the moment since the resource is not burstable.". So I wonder if we need to prohibit defining limits for extended resources in the validation func |
@lichuqiang Okay, after checking the code another time, I realized that I was misunderstanding the code. The said situation is not happening. I'm deleting my comments in case it confuses other reviewers. |
@lichuqiang how to use this for GPU quota, are there some docs? do we need to enable deviceplugin feature gate? |
@pineking As the resource name of GPU(alpha.kubernetes.io/nvidia-gpu) is in format of extended resource, you don't need extra operation for resource quota. |
@lichuqiang thanks, got it, I use the “old way” to enable GPU. |
code logic wise LGTM. |
Oh, sorry. Just realized that we may need to hold this before claiming we support quota for extended resources. I think it is a bug introduced in #56818. Take the following Pod spec as an example:
The current device reuse logic will first recognize the 4 GPU requests from init containers, then reuse 2 of them to the regular container C. So the total GPU requests from the pod is 4. However, the quota check logic today ( https://github.com/kubernetes/kubernetes/blob/master/pkg/quota/evaluator/core/pods.go#L322-L332 ) computes the resource requests differently. It will do This problem is being fixed (as a side-effect) in #53698. |
@tengqm Oh, I think you should take another look at #56818, device reuse between init containers is supported, we would only recognize 2 GPU in your case. |
@tengqm Agree with @lichuqiang, code walk through suggests current device reuse logic will count 2 GPUs only. For second init container, first devices will be picked from already allocated devices. |
Ah, yes. Walked through the code again. I didn't quite get the tricks to build device id unions. Seems not a problem then. |
InitContainers: []api.Container{{ | ||
Resources: api.ResourceRequirements{ | ||
Requests: api.ResourceList{api.ResourceName("example.com/dongle"): resource.MustParse("3")}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should Limits also be mentioned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to add Limits for consistency, even though it may not affect this test.
@lichuqiang Perhaps you merge two commits will be better. |
@@ -75,6 +75,10 @@ func validateContainerResourceName(value string, fldPath *field.Path) field.Erro | |||
if !helper.IsStandardContainerResourceName(value) { | |||
return append(allErrs, field.Invalid(fldPath, value, "must be a standard resource for containers")) | |||
} | |||
} else if !v1helper.IsDefaultNamespaceResource(v1.ResourceName(value)) { | |||
if !v1helper.IsExtendedResourceName(v1.ResourceName(value)) { | |||
return append(allErrs, field.Invalid(fldPath, value, "doesn't follow extended resource name standard")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/name/naming/g
// 1. the resource name is not in the default namespace; | ||
// 2. resource name does not have "requests." prefix, | ||
// to avoid confusion with the convention in quota | ||
// 3. it satisfies the rules in IsQualifiedName() after converted into quota resource name | ||
func IsExtendedResourceName(name core.ResourceName) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any unit tests for this method? If so can you add test cases for each of the scenario you mention in the comment, including maximum length validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a follow-on w/ tests would be good for this.
@@ -4159,6 +4159,8 @@ const ( | |||
// HugePages request, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) | |||
// As burst is not supported for HugePages, we would only quota its request, and ignore the limit. | |||
ResourceRequestsHugePagesPrefix = "requests.hugepages-" | |||
// Default resource requests prefix | |||
DefaultResourceRequestsPrefix = "requests." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@derekwaynecarr Do we still need explicit types for first class resources or can we apply the logic this PR employs for first class resources too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suspect we could consolidate logic now to say any compute resource (cpu, memory, etc.) could support requests.* or limits.* syntax is overcommittable.
/approve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this useful feature.
// 1. the resource name is not in the default namespace; | ||
// 2. resource name does not have "requests." prefix, | ||
// to avoid confusion with the convention in quota | ||
// 3. it satisfies the rules in IsQualifiedName() after converted into quota resource name | ||
func IsExtendedResourceName(name core.ResourceName) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a follow-on w/ tests would be good for this.
@@ -4159,6 +4159,8 @@ const ( | |||
// HugePages request, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) | |||
// As burst is not supported for HugePages, we would only quota its request, and ignore the limit. | |||
ResourceRequestsHugePagesPrefix = "requests.hugepages-" | |||
// Default resource requests prefix | |||
DefaultResourceRequestsPrefix = "requests." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suspect we could consolidate logic now to say any compute resource (cpu, memory, etc.) could support requests.* or limits.* syntax is overcommittable.
/approve |
/retest pull-kubernetes-verify |
/assign @thockin @dchen1107 for approval |
@jiayingz: GitHub didn't allow me to assign the following users: for, approval. Note that only kubernetes members and repo collaborators can be assigned. In response to this:
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. |
/retest pull-kubernetes-verify |
/approve thanks for the feature! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dchen1107, derekwaynecarr, jiayingz, lichuqiang, vishh 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 |
/retest Review the full test history for this PR. Silence the bot with an |
/test all Tests are more than 96 hours old. Re-running tests. |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
@lichuqiang are there some docs to tell how to use this feature for extended resources, e.g. "nvidia.com/gpu" |
@pineking Not yet, I'll post a PR to update the quota doc soon. Pod example:
quota example:
|
@lichuqiang I have tested this feature. It works! Thanks. |
@lichuqiang Can you update the docs with how to set this? |
docs update PR posted: kubernetes/website#7936 |
Which issue(s) this PR fixes :
Fixes #46639 #57300 for resource quota support
Special notes for your reviewer:
One thing to be determined is if it necessary to Explicitly prohibit defining limits for extended resources in quota, like we did for hugepages, as the resource is not allowed to overcommit.
Release note:
/cc @jiayingz @vishh @derekwaynecarr