Skip to content

Conversation

kincoy
Copy link
Contributor

@kincoy kincoy commented Aug 5, 2025

What type of PR is this?

/kind cleanup


What this PR does / why we need it:

This PR improves unit test coverage for several utility functions in core/utils, helping ensure correctness and robustness of logic that supports autoscaling decisions.

Specifically:

  • Adds unit tests for:
    • FilterOutNodesFromNotAutoscaledGroups
    • GetOldestCreateTimeWithGpu
    • hasHardInterPodAffinity
    • isVirtualNode
  • Fixes potential panic in isVirtualNode when passed a nil node
  • Brings test coverage in core/utils/utils.go from 47.4% to 84.6%

before:
image

after:
image


Which issue(s) this PR fixes:

N/A — test coverage improvement


Special notes for your reviewer:

  • Safe refactor: no production logic changed, only a nil check added in isVirtualNode
  • Tests are table-driven and use testify assertions

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area labels Aug 5, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kincoy
Once this PR has been reviewed and has the lgtm label, please assign feiskyer 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

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @kincoy. 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 added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 5, 2025
@kincoy
Copy link
Contributor Author

kincoy commented Aug 13, 2025

@feiskyer @vadasambar Hi, could you please re-run the failed workflows? They appear to be unrelated to this PR. Thanks🙏!

@vadasambar
Copy link
Member

vadasambar commented Aug 13, 2025

@kincoy sorry I don't have permissions to restart the failed workflow. Can you try creating an empty commit like this to trigger the build (another option is to create a small harmless change like adding new line and removing it later):

git commit --allow-empty -m "Trigger Build"

@kincoy kincoy force-pushed the test/core-utils-cover branch 2 times, most recently from 210db02 to b585c82 Compare August 13, 2025 13:31
@kincoy
Copy link
Contributor Author

kincoy commented Aug 13, 2025

@kincoy sorry I don't have permissions to restart the failed workflow. Can you try creating an empty commit like this to trigger the build (another option is to create a small harmless change like adding new line and removing it later):

git commit --allow-empty -m "Trigger Build"

Thanks for your feedback. I found a minor issue in my changes, which has now been fixed. I’ve pushed the update and all tests have passed. Please help review the latest commit to see if it looks good. Thanks again!🙏。

@kincoy kincoy force-pushed the test/core-utils-cover branch from b585c82 to a21eb0e Compare August 13, 2025 14:40
@jackfrancis
Copy link
Contributor

/ok-to-test

@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. release-note-none Denotes a PR that doesn't merit a release note. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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 Aug 13, 2025
// isVirtualNode determines if the node is created by virtual kubelet
func isVirtualNode(node *apiv1.Node) bool {
return node.ObjectMeta.Labels["type"] == "virtual-kubelet"
if node == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

return node != nil && node.ObjectMeta.Labels["type"] == VirtualKubeletNodeLabelValue is more concise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I agree the one-liner is more concise, but I opted for the explicit if node == nil form to improve readability and maintainability.

It's quite common to use explicit nil checks, especially when dealing with nested struct access, as it allows easier debugging and extension in the future (e.g., adding logs or metrics inside the nil branch).

Happy to change if we prefer the concise form globally.

@kincoy kincoy force-pushed the test/core-utils-cover branch from a21eb0e to 00a5c3e Compare August 15, 2025 02:27
@kincoy
Copy link
Contributor Author

kincoy commented Sep 1, 2025

Friendly ping @jackfrancis — this PR has been idle for a while. Would appreciate a review when convenient 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cluster-autoscaler 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants