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

Remove missing extended resources from init containers #124273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

panoswoo
Copy link

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?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Apr 11, 2024
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.30 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.30.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Thu Apr 11 13:45:22 UTC 2024.

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 11, 2024
Copy link

linux-foundation-easycla bot commented Apr 11, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: panoswoo / name: Panos Woo (fbb975b)

@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 11, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @panoswoo!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 11, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: panoswoo
Once this PR has been reviewed and has the lgtm label, please assign yujuhong for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 11, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 11, 2024
@haircommander
Copy link
Contributor

/ok-to-test
/triage accepted
/priority important-longterm

LGTM, let's see how tests feel but this seems like a straight forward fix

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 11, 2024
@panoswoo
Copy link
Author

/ok-to-test

/triage accepted

/priority important-longterm

LGTM, let's see how tests feel but this seems like a straight forward fix

Tests are all good, lgtm plz :)

@bart0sh bart0sh added this to Triage in SIG Node PR Triage Apr 11, 2024
}
podCopy.Spec.InitContainers[i].Resources.Requests[rName] = rQuant
}
}
Copy link
Contributor

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?

Copy link
Author

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?

Copy link
Contributor

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
}

Copy link
Author

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
}

Copy link
Contributor

Choose a reason for hiding this comment

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

/lgtm

@bart0sh bart0sh moved this from Triage to Needs Reviewer in SIG Node PR Triage Apr 11, 2024
Signed-off-by: Panos Woo <panoswoo@outlook.com>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 12, 2024
@panoswoo panoswoo requested a review from bart0sh April 12, 2024 14:20
@panoswoo
Copy link
Author

/retest

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

LGTM label has been added.

Git tree hash: 68528a8c71c17b3502aadcfec4c0a89f975e0ec8

@bart0sh
Copy link
Contributor

bart0sh commented Apr 12, 2024

/assign @mrunalp @derekwaynecarr @dchen1107
for approval

@bart0sh bart0sh moved this from Needs Reviewer to Needs Approver in SIG Node PR Triage Apr 12, 2024
@panoswoo
Copy link
Author

@mrunalp @derekwaynecarr @dchen1107 PTAL~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubelet 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Needs Approver
SIG Node PR Triage
Needs Approver
Development

Successfully merging this pull request may close these issues.

removeMissingExtendedResources() did not remove unknown extension resources from InitContainer
8 participants