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

✨ (go/v4): Add tests for the webhooks and controllers which are created so that suite_test are no longer ignored #3631

Merged
merged 1 commit into from Nov 2, 2023

Conversation

dashanji
Copy link
Contributor

@dashanji dashanji commented Sep 17, 2023

How to reproduce?

Add any valid ginkgo assert such as Expect(1).To(Equal(2)) to the BeforeSuite and AfterSuite. As a result, the test should fail, but it succeeds actually.

What do these changes do?

Add the unit test template for webhook and controllers so that suite_test are no longer ignored.

Fixes #3646

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 17, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @dashanji!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. 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-sigs/kubebuilder 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-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 17, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @dashanji. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@dashanji dashanji changed the title bugfix: Fix the BeforeSuite and AfterSuite modules not running in the ginkgo v2 bug: Fix the BeforeSuite and AfterSuite modules not running in the ginkgo v2 Sep 17, 2023
@dashanji dashanji changed the title bug: Fix the BeforeSuite and AfterSuite modules not running in the ginkgo v2 🌱 bugfix: Fix the BeforeSuite and AfterSuite modules not running in the ginkgo v2 Sep 18, 2023
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Tests should not be automatically added to the suite_test by default. Remember, the scaffold primarily sets up the suite_test, but it doesn't generate tests for individual API/controllers or webhooks.

Given this, I'm curious: under what circumstances would you add assert checks to the Before/AfterSuite without first implementing comprehensive tests for each controller and/or webhook, especially in light of the issue scenario you've described? Could you please provide more details on this?

Moreover, if we do opt to include placeholder tests to address this concern, we should:

  • Scaffold a distinct test file for each controller and webhook.
  • Consider including a basic test case that would universally be valid, or at the very least, include a TODO(user): note guiding users on the next steps. For reference, you might want to check out the source code—particularly the reconcile method and the accompanying TODO comments.
  • Lastly, we might need to perform small changes to the implementation of the deploy image plugin since this one scaffold tests for each controller by default. See: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go (**Probably just add m.IfExistsAction = OverwriteFile into this template is enough so that we will re-write the controller test if any be scaffolded already)

So, what do you think?
Could you change it accordingly?

@dashanji
Copy link
Contributor Author

Given this, I'm curious: under what circumstances would you add assert checks to the Before/AfterSuite without first implementing comprehensive tests for each controller and/or webhook, especially in light of the issue scenario you've described? Could you please provide more details on this?

Hi, @camilamacedo86, thanks for the details. Actually, in ginkgo v1, the BeforeSuite and AfterSuite can run successfully, so users can test the default case(CRDs, Controllers, and Webhooks can be installed successfully, just as what BeforeSuite does) without any changes just running make test. My point is to reserve the same adaption for users in the newest kubebuilder(v4). I don't know whether it makes sense to the community.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 19, 2023
@camilamacedo86
Copy link
Member

camilamacedo86 commented Sep 29, 2023

Hi, @camilamacedo86, thanks for the details. Actually, in ginkgo v1, the BeforeSuite and AfterSuite can run successfully, so users can test the default case(CRDs, Controllers, and Webhooks can be installed successfully, just as what BeforeSuite does) without any changes just running make test. My point is to reserve the same adaption for users in the newest kubebuilder(v4). I don't know whether it makes sense to the community.

Can you please describe what problem and when are you facing it?
If I create a new project (kubebuilder init)
Scaffold an API (kubebuilder create api)
Run (make test)

All works fine. So, can you pelase raise an issue with:

  • What are the steps that you are performing
  • What would like to see
  • What are you checking instead?

@dashanji
Copy link
Contributor Author

dashanji commented Oct 1, 2023

Hi, @camilamacedo86, thanks for the details. Actually, in ginkgo v1, the BeforeSuite and AfterSuite can run successfully, so users can test the default case(CRDs, Controllers, and Webhooks can be installed successfully, just as what BeforeSuite does) without any changes just running make test. My point is to reserve the same adaption for users in the newest kubebuilder(v4). I don't know whether it makes sense to the community.

Can you please describe what problem and when are you facing it? If I create a new project (kubebuilder init) Scaffold an API (kubebuilder create api) Run (make test)

All works fine. So, can you pelase raise an issue with:

  • What are the steps that you are performing
  • What would like to see
  • What are you checking instead?

Thanks for the advice, I just opened an issue that can reproduce the bug.
#3646, FYI.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 7, 2023
@dashanji
Copy link
Contributor Author

dashanji commented Oct 7, 2023

Hi, @camilamacedo86 Could you please take another review? Thanks.

@dashanji dashanji force-pushed the fix-ginkgo-test branch 2 times, most recently from 9493187 to f04e5a8 Compare October 8, 2023 09:39
@Sajiyah-Salat
Copy link
Contributor

Sajiyah-Salat commented Oct 9, 2023

@dashanji one thing that I noticed is common that there is a func() keywork everywhere in the code. I tried to find its origin and the logic it contains. I didnt find it till now through ide. I know this is a sillly question. But can you tell me whats the logic wriiten in func() keyword. or guide me to its origin and I will find it by my own.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Great work 🥇
Just a few nits:

  • We should not scaffold a code that is not valid. So, for the webhooks under the test add a TODO(user): Add your logic here as we do for the reconcile and it is fine
  • We should not change the go/v3 since it is deprecated. Can you please revert the changes and re-run make generate?
  • The title of the PR we use to generate the changelog, I will update it accordingly to try to help out but you can check more about it in the CONTRIBUTION.md guide

After the changes please ensure that we have only 1 commit as of now so that we can get this one merged. You can squash the commits.

@camilamacedo86 camilamacedo86 changed the title 🌱 bugfix: Fix the BeforeSuite and AfterSuite modules not running in the ginkgo v2 ✨ (go/v4): Add tests for the webhooks and controllers which are created so that suite_test are no longer ignored Oct 9, 2023
@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 9, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 9, 2023
@dashanji
Copy link
Contributor Author

dashanji commented Oct 9, 2023

@dashanji one thing that I noticed is common that there is a func() keywork everywhere in the code. I tried to find its origin and the logic it contains. I didnt find it till now through ide. I know this is a sillly question. But can you tell me whats the logic wriiten in func() keyword. or guide me to its origin and I will find it by my own.

Hi, @Sajiyah-Salat. A possible way is to debugging the kubebuilder create api/webhook then you can see the complete execution order.

The webhook test is generated here and its logic code is here.

The controller test is generated here and its logic code is here. FYI.

@dashanji
Copy link
Contributor Author

dashanji commented Oct 9, 2023

Great work 🥇 Just a few nits:

  • We should not scaffold a code that is not valid. So, for the webhooks under the test add a TODO(user): Add your logic here as we do for the reconcile and it is fine
  • We should not change the go/v3 since it is deprecated. Can you please revert the changes and re-run make generate?
  • The title of the PR we use to generate the changelog, I will update it accordingly to try to help out but you can check more about it in the CONTRIBUTION.md guide

After the changes please ensure that we have only 1 commit as of now so that we can get this one merged. You can squash the commits.

Make sense to me.

@dashanji dashanji force-pushed the fix-ginkgo-test branch 2 times, most recently from 54748ad to e0507cb Compare October 9, 2023 17:39
…test are no longer ignored.

Signed-off-by: dashanji <dashanjic@gmail.com>
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

It shows great for me
I am approving

But would be nice see if we get a second reviewer as well
Let's try, if nobody be able to do this review I can either lgtm after a while

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 10, 2023
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

@varshaprasad96 @everettraven @Kavinjsir

It seems OK for me.
Since it is open for a while I will /lgtm
otherwise the author might need to rebase this one

However, if you have suggestions/objections and etc we can always address in a follow up.

@camilamacedo86
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 2, 2023
@k8s-ci-robot k8s-ci-robot merged commit 8c7074e into kubernetes-sigs:master Nov 2, 2023
18 checks passed
Copy link
Contributor

@Kavinjsir Kavinjsir left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, dashanji, Kavinjsir

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@dashanji dashanji deleted the fix-ginkgo-test branch December 23, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BeforeSuite and AfterSuite modules not running in the ginkgo v2
5 participants