Skip to content

remove assert/require lib from scheduler pkg #131145

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

mohitsethia
Copy link

@mohitsethia mohitsethia commented Apr 1, 2025

What type of PR is this?

/sig scheduling
/kind cleanup

What this PR does / why we need it: According to the sig guidelines, we should use cmp.Equal or cmp.Diff instead of assert & require libraries

Which issue(s) this PR fixes: #130407

Fixes #130407

Special notes for your reviewer:

Does this PR introduce a user-facing change?


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


@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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 sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 1, 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
Copy link
Contributor

Welcome @mohitsethia!

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 k8s-ci-robot added 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 Apr 1, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @mohitsethia. 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 bart0sh and jingxu97 April 1, 2025 18:34
@k8s-ci-robot k8s-ci-robot added sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. wg/device-management Categorizes an issue or PR as relevant to WG Device Management. labels Apr 1, 2025
@googs1025
Copy link
Member

googs1025 commented Apr 2, 2025

Can you follow the original author's comment?
base on:
#130407 (comment)

or You don't need to use a new pr, but can continue to complete the work directly on that pr.

@googs1025
Copy link
Member

or you can use git commit --author xxxx to name the co-author

@googs1025
Copy link
Member

Can you follow the original author's comment? base on: #130407 (comment)

or You don't need to use a new pr, but can continue to complete the work directly on that pr.

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 2, 2025
@mohitsethia
Copy link
Author

Hi @googs1025 , I had forked the repo with only the master branch. So, it was not possible for me to use that branch.

@googs1025
Copy link
Member

I had forked the repo with only the master branch. So, it was not possible for me to use that branch.

can you pull his branch down without recreating?

@mohitsethia
Copy link
Author

mohitsethia commented Apr 2, 2025

Since this is already created, does it make sense to simply close that PR? And to pull his branch, I again have to clone his forked repo. I am sorry but I think this would only complicate (bad choice of word) and since the PR is already created, and I have already worked on this one, more changes than the previous PR.

@googs1025
Copy link
Member

googs1025 commented Apr 2, 2025

@mohitsethia
Why do you need to fork his repository? Maybe you just need to use git remote add xxx 🤔

Since this is already created, does it make sense to simply close that PR?

base on:
#130407 (comment)
Maybe we should respect previous committers?

Or you need to indicate the collaborators in your PR. like this: #131145 (comment)

@mohitsethia mohitsethia force-pushed the remove-assert-lib-in-scheduler-tests branch from 726b639 to 42be468 Compare April 10, 2025 20:29
@mohitsethia
Copy link
Author

/test pull-kubernetes-e2e-gce

@@ -1163,7 +1172,9 @@ func (tc *testContext) verify(t *testing.T, expected result, initialObjects []me
func (tc *testContext) listAll(t *testing.T) (objects []metav1.Object) {
t.Helper()
claims, err := tc.client.ResourceV1beta1().ResourceClaims("").List(tc.ctx, metav1.ListOptions{})
require.NoError(t, err, "list claims")
if err != nil {
t.Errorf("unexpected error in list claims: %s", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to call .Error() if passing is as an argument to the t.Errorf:

Suggested change
t.Errorf("unexpected error in list claims: %s", err.Error())
t.Errorf("unexpected error in list claims: %s", err)

if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
}
if diff := cmp.Diff(tc.expectedHint, actualHint); diff != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Using cmp.Diff on an int value is probably too much and just an equality check could be enough.

}

func verifyEmpty(t *testing.T, queue *FIFO[int]) {
t.Helper()
require.Equal(t, 0, queue.Len())
if !cmp.Equal(0, queue.Len()) {
Copy link
Member

Choose a reason for hiding this comment

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

For simple equality check it's not needed to use cmp.Equal:

Suggested change
if !cmp.Equal(0, queue.Len()) {
if queue.Len() != 0 {

Copy link
Author

@mohitsethia mohitsethia Apr 17, 2025

Choose a reason for hiding this comment

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

I don't know why I didn't receive any notifications for these comments. The comment totally makes sense, fixed all the comments now.

@mohitsethia
Copy link
Author

Hi , does any one know what seems to be the error in the e2e-gce test? Could it be a flaky test?

@macsko
Copy link
Member

macsko commented Apr 11, 2025

Hi , does any one know what seems to be the error in the e2e-gce test? Could it be a flaky test?

Looks like a flaky test

/retest

@dgrisonnet
Copy link
Member

/remove-sig instrumentation

@k8s-ci-robot k8s-ci-robot removed the sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. label Apr 17, 2025
@mohitsethia mohitsethia force-pushed the remove-assert-lib-in-scheduler-tests branch 2 times, most recently from fea491c to b4bb6dc Compare April 17, 2025 21:24
@@ -99,19 +111,31 @@ func TestShrink(t *testing.T) {
for i := 0; i < normalSize*2; i++ {
queue.Push(i)
}
require.Equal(t, normalSize*2, queue.Len())
require.LessOrEqual(t, 2*normalSize, len(queue.elements))
if !cmp.Equal(normalSize*2, queue.Len()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if !cmp.Equal(normalSize*2, queue.Len()) {
if queue.Len() != normalSize*2 {

if !cmp.Equal(normalSize*2, queue.Len()) {
t.Errorf("Expected queue len as %d, actual len: %d", normalSize*2, queue.Len())
}
if 2*normalSize > len(queue.elements) {
Copy link
Member

Choose a reason for hiding this comment

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

Flip the args:

Suggested change
if 2*normalSize > len(queue.elements) {
if len(queue.elements) < 2*normalSize {

if queue.Len() != 0 {
t.Errorf("Expected queue len as 0, actual len: %d", queue.Len())
}
if !cmp.Equal(normalSize, len(queue.elements)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if !cmp.Equal(normalSize, len(queue.elements)) {
if len(queue.elements) != normalSize {

if queue.Len() != 0 {
t.Errorf("Expected queue len as 0, actual len: %d", queue.Len())
}
if normalSize != len(queue.elements) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if normalSize != len(queue.elements) {
if len(queue.elements) != normalSize {

Comment on lines 28 to 31
if !cmp.Equal(expectedOk, ok) {
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok)
}
if !cmp.Equal(expectedValue, actual) {
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if !cmp.Equal(expectedOk, ok) {
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok)
}
if !cmp.Equal(expectedValue, actual) {
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual)
}
if ok != expectedOk {
t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok)
}
if actual != expectedValue {
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual)
}

Copy link
Author

Choose a reason for hiding this comment

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

Shall I resolve all the conversation? Or wait for the commentor to do it?

Comment on lines 1121 to 1122
if expected.status == nil && status != nil {
t.Errorf("Expected nil status but got: %+v", status)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe keep the previous logic:

Suggested change
if expected.status == nil && status != nil {
t.Errorf("Expected nil status but got: %+v", status)
if expected.status == nil {
if status != nil {
t.Errorf("Expected nil status but got: %+v", status)
}

Copy link
Author

Choose a reason for hiding this comment

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

I got a comment to simplify it 😅

@mohitsethia mohitsethia force-pushed the remove-assert-lib-in-scheduler-tests branch from b4bb6dc to 6ad0083 Compare April 18, 2025 09:58
@mohitsethia mohitsethia requested a review from macsko April 23, 2025 08:07
@SergeyKanzhelev SergeyKanzhelev moved this from Triage to Archive-it in SIG Node CI/Test Board Apr 23, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 23, 2025
@BenTheElder
Copy link
Member

/remove-area dependency
needs rebase

@k8s-ci-robot k8s-ci-robot removed the area/dependency Issues or PRs related to dependency changes label Apr 25, 2025
@mohitsethia mohitsethia force-pushed the remove-assert-lib-in-scheduler-tests branch from 6ad0083 to 09376ee Compare April 26, 2025 21:02
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2025
@mohitsethia
Copy link
Author

/test pull-kubernetes-unit

@mohitsethia
Copy link
Author

Hi, can we merge the PR now, or is there anything that is blocking it for now?

@mohitsethia
Copy link
Author

Hi @macsko, can you please help me letting know what is the next action to be taken for this PR?

Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

/remove-area kubeadm
/remove-sig cluster-lifecycle

@k8s-ci-robot k8s-ci-robot removed area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. labels May 6, 2025
@aramase aramase moved this from Needs Triage to !SIG Auth in SIG Auth May 12, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 7, 2025
Copy link
Member

@macsko macsko left a comment

Choose a reason for hiding this comment

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

Please rebase and check if after rebasing no new assert/require usages appear.

@@ -1163,7 +1174,9 @@ func (tc *testContext) verify(t *testing.T, expected result, initialObjects []me
func (tc *testContext) listAll(t *testing.T) (objects []metav1.Object) {
t.Helper()
claims, err := tc.client.ResourceV1beta1().ResourceClaims("").List(tc.ctx, metav1.ListOptions{})
require.NoError(t, err, "list claims")
if err != nil {
t.Errorf("unexpected error in list claims: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

Change to t.Fatalf everywhere where require was used

if err != nil {
t.Errorf("Unexpected error in isSchedulableAfterPodDeleted: %s", err.Error())
}
if diff := cmp.Diff(tc.expectedHint, actualHint); diff != "" {
Copy link
Member

Choose a reason for hiding this comment

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

It's an integer. You could just do comparison (tc.expectedHint != actualHint). It would be good to print them in error message as strings (use %s).

Copy link
Member

Choose a reason for hiding this comment

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

And change it similarly for other plugins

require.NoError(t, err)
require.Equal(t, tc.expectedHint, actualHint)
if err != nil {
t.Errorf("Unexpected error in isSchedulableAfterNodeChange: %s", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

You can skip .Error() here. Please change it in other places as well:

Suggested change
t.Errorf("Unexpected error in isSchedulableAfterNodeChange: %s", err.Error())
t.Errorf("Unexpected error in isSchedulableAfterNodeChange: %s", err)

t.Errorf("Expected queue.Pop() status: %t, actual status: %t", expectedOk, ok)
}
if actual != expectedValue {
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Expected queue.Pop() value: %d, actual status: %d", expectedValue, actual)
t.Errorf("Expected queue.Pop() value: %d, actual value: %d", expectedValue, actual)

}

func verifyEmpty(t *testing.T, queue *FIFO[int]) {
t.Helper()
require.Equal(t, 0, queue.Len())
if queue.Len() != 0 {
t.Errorf("Expected empty queue, actual Len: %d", queue.Len())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Expected empty queue, actual Len: %d", queue.Len())
t.Errorf("Expected empty queue, actual len: %d", queue.Len())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver area/cloudprovider area/code-generation area/kube-proxy area/kubectl area/kubelet area/provider/gcp Issues or PRs related to gcp provider area/release-eng Issues or PRs related to the Release Engineering subproject area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/etcd Categorizes an issue or PR as relevant to SIG Etcd. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/release Categorizes an issue or PR as relevant to SIG Release. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.
Projects
Archived in project
Status: Needs Triage
Status: !SIG Auth
Status: Needs Triage
Status: Archive-it
Status: other-sig (sig-node-approved)
Development

Successfully merging this pull request may close these issues.

Remove usage of assertion libraries in pkg/scheduler tests