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
Remove missing extended resources from init containers #124273
base: master
Are you sure you want to change the base?
Conversation
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Thu Apr 11 13:45:22 UTC 2024. |
|
Welcome @panoswoo! |
Hi @panoswoo. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: panoswoo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test LGTM, let's see how tests feel but this seems like a straight forward fix |
Tests are all good, lgtm plz :) |
} | ||
podCopy.Spec.InitContainers[i].Resources.Requests[rName] = rQuant | ||
} | ||
} |
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 code looks almost identical to the code above. Would it be possible to avoid duplication somehow?
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’ll extract the duplicate code into a new function. Should I add this code to a new commit or just amend the existing one?
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 would propose this to not replicate the code:
func removeMissingExtendedResources(pod *v1.Pod, nodeInfo *schedulerframework.NodeInfo) *v1.Pod {
podCopy := pod.DeepCopy()
updateResourceRequests := func(containers []v1.Container) []v1.Container {
for i, container := range containers {
// We only handle requests in Requests but not Limits because the
// PodFitsResources predicate, to which the result pod will be passed,
// does not use Limits.
container.Resources.Requests = filterExtendedResources(container.Resources.Requests, nodeInfo)
containers[i] = container
}
return containers
}
podCopy.Spec.Containers = updateResourceRequests(podCopy.Spec.Containers)
podCopy.Spec.InitContainers = updateResourceRequests(podCopy.Spec.InitContainers)
return podCopy
}
func filterExtendedResources(requests v1.ResourceList, nodeInfo *schedulerframework.NodeInfo) v1.ResourceList {
filteredRequests := make(v1.ResourceList)
for rName, rQuant := range requests {
if v1helper.IsExtendedResourceName(rName) {
if _, found := nodeInfo.Allocatable.ScalarResources[rName]; !found {
continue
}
}
filteredRequests[rName] = rQuant
}
return filteredRequests
}
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.
nice suggestion, I plan to modify it like this:
func removeMissingExtendedResources(pod *v1.Pod, nodeInfo *schedulerframework.NodeInfo) *v1.Pod {
filterExtendedResources := func(containers []v1.Container) {
for i, c := range containers {
// We only handle requests in Requests but not Limits because the
// PodFitsResources predicate, to which the result pod will be passed,
// does not use Limits.
filteredResources := make(v1.ResourceList)
for rName, rQuant := range c.Resources.Requests {
if v1helper.IsExtendedResourceName(rName) {
if _, found := nodeInfo.Allocatable.ScalarResources[rName]; !found {
continue
}
}
filteredResources[rName] = rQuant
}
containers[i].Resources.Requests = filteredResources
}
}
podCopy := pod.DeepCopy()
filterExtendedResources(podCopy.Spec.Containers)
filterExtendedResources(podCopy.Spec.InitContainers)
return podCopy
}
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.
/lgtm
Signed-off-by: Panos Woo <panoswoo@outlook.com>
/retest |
LGTM label has been added. Git tree hash: 68528a8c71c17b3502aadcfec4c0a89f975e0ec8
|
/assign @mrunalp @derekwaynecarr @dchen1107 |
What type of PR is this?
/kind bug
What this PR does / why we need it:
The function removeMissingExtendedResources() located at pkg/kubelet/lifecycle/predicate.go:217, is designed to remove any extended resources from a container’s requests that are not found in nodeInfo.Allocatable before the pod is admitted.
This is necessary to support cluster-level resources, which are extended resources that are unknown to nodes.
However, this function only removes missingExtendedResources from the container’s requests, and does not process the requests of initContainers.
This could lead to issues, as initContainers might request resources that do not exist on the node, which could result in the pod failing to be admitted or other unforeseen issues.
Which issue(s) this PR fixes:
Fixes #124255
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: