Skip to content

test: code coverage increase for kubelet/preemption #132607

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

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

Conversation

ylink-lfs
Copy link
Contributor

@ylink-lfs ylink-lfs commented Jun 29, 2025

What type of PR is this?

/kind cleanup
/sig node

What this PR does / why we need it:

Test coverage increase for kubelet package

Which issue(s) this PR is related to:

Part of #109717

Special notes for your reviewer:

Before the commits are made, the coverage of kubelet-client is 74.5%:

➜  kubernetes git:(master) make test WHAT=./pkg/kubelet/preemption KUBE_COVER=y GOFLAGS=-v
+++ [0629 23:54:13] Set GOMAXPROCS automatically to 8
+++ [0629 23:54:13] Normalizing Go targets
+++ [0629 23:54:13] Saving coverage output in '/tmp/k8s_coverage/20250629-235413'
+++ [0629 23:54:13] Running tests with code coverage and with -race
✓  pkg/kubelet/preemption (2.109s) (coverage: 74.5% of statements)

DONE 29 tests in 10.795s
+++ [0629 23:54:25] Combined coverage report: /tmp/k8s_coverage/20250629-235413/combined-coverage.html

This commit increases the coverage to 89.8%:

➜  kubernetes git:(test/kubelet_preemption_test) make test WHAT=./pkg/kubelet/preemption KUBE_COVER=y GOFLAGS=-v
+++ [0629 23:53:29] Set GOMAXPROCS automatically to 8
+++ [0629 23:53:29] Normalizing Go targets
+++ [0629 23:53:29] Saving coverage output in '/tmp/k8s_coverage/20250629-235329'
+++ [0629 23:53:29] Running tests with code coverage and with -race
✓  pkg/kubelet/preemption (2.196s) (coverage: 89.8% of statements)

DONE 38 tests in 16.556s
+++ [0629 23:53:47] Combined coverage report: /tmp/k8s_coverage/20250629-235329/combined-coverage.html

Note that function evictPodsToFreeRequests is only called by HandleAdmissionFailure, so changing UT related to evictPodsToFreeRequests to HandleAdmissionFailure should be a safe change.

Does this PR introduce a user-facing change?

NONE

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

NONE

@Copilot Copilot AI review requested due to automatic review settings June 29, 2025 15:56
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. sig/node Categorizes an issue or PR as relevant to SIG Node. labels Jun 29, 2025
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 29, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 29, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @ylink-lfs. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot requested review from mrunalp and odinuge June 29, 2025 15:57
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ylink-lfs
Once this PR has been reviewed and has the lgtm label, please assign sjenning for approval. For more information see the 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

Copilot

This comment was marked as outdated.

@ylink-lfs
Copy link
Contributor Author

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 29, 2025
@ylink-lfs ylink-lfs force-pushed the test/kubelet_preemption_test branch from 48a3365 to d1b088c Compare June 29, 2025 16:00
@ylink-lfs ylink-lfs changed the title test: code coverage increase for kubelet/preemption.go test: code coverage increase for kubelet/preemption Jun 29, 2025
@ylink-lfs ylink-lfs force-pushed the test/kubelet_preemption_test branch from d1b088c to 9b0d973 Compare June 30, 2025 02:48
@ylink-lfs ylink-lfs requested a review from Copilot June 30, 2025 02:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves unit test coverage for the pkg/kubelet/preemption package by refactoring the existing eviction test, adding new test scenarios for failure reasons, and introducing a focused test for resource‐comparison logic.

  • Renamed and expanded TestEvictPodsToFreeRequests to TestHandleAdmissionFailure, now covering multiple failure scenarios and filtering reasons.
  • Added TestSmallerResourceRequest to validate the smallerResourceRequest function across diverse resource combinations.
  • Introduced getPredicateFailureReasons helper to simulate predicate failures in tests.
Comments suppressed due to low confidence (2)

pkg/kubelet/preemption/preemption_test.go:199

  • The %b verb is for binary formatting of integers, but r.expectReasons is a slice. Use %v or %#v to format slices correctly.
				t.Fatalf("expect reasons %b, got reasons %v", r.expectReasons, filteredReason)

pkg/kubelet/preemption/preemption_test.go:638

  • [nitpick] The parameter otherReasonExist could be clearer. Consider renaming it to includeOtherReason or hasOtherReason to better convey its boolean intent.
func getPredicateFailureReasons(insufficientCPU, insufficientMemory, insufficientPods int, otherReasonExist bool) (reasonByPredicate []lifecycle.PredicateFailureReason) {

@ylink-lfs ylink-lfs force-pushed the test/kubelet_preemption_test branch from 9b0d973 to 21ccc7c Compare June 30, 2025 02:56
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Development

Successfully merging this pull request may close these issues.

2 participants