-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
WIP fix: standardize scaffold suite_test files #4441
WIP fix: standardize scaffold suite_test files #4441
Conversation
Signed-off-by: Mateus Oliveira <msouzaol@redhat.com>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mateusoliveira43 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 |
Hi @mateusoliveira43. 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 Once the patch is verified, the new status will be reflected by the 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. |
Signed-off-by: Mateus Oliveira <msouzaol@redhat.com>
By("bootstrapping test environment") | ||
testEnv = &envtest.Environment{ | ||
CRDInstallOptions: envtest.CRDInstallOptions{Scheme: scheme.Scheme}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made this change because of this kubernetes-sigs/controller-runtime#1882 (comment)
@@ -56,12 +56,12 @@ Now, let's go through the code generated. | |||
*/ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit:
Any change that impacts the scaffolds will directly affect end users and, therefore, cannot be marked with 🌱. Please note that these emojis are used to help us generate the release notes. Both 🌱 and 📖 lead to items being listed only under the "All changes" section and not highlighted in the main release notes. While 🌱 is appropriate for test-related changes, in this case, since we're modifying the default scaffolds, it should not be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated PR title
docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go
Show resolved
Hide resolved
docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go
Show resolved
Hide resolved
batchv1 "tutorial.kubebuilder.io/project/api/v1" | ||
|
||
// +kubebuilder:scaffold:imports | ||
apimachineryruntime "k8s.io/apimachinery/pkg/runtime" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this one not used?
If so good catcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was
I removed because webhooks suite test used an "empty" scheme (with only user CRDs) and controllers suite test used a "fully loaded" scheme (with user CRDs and default objects loaded, like namespaces, pods, etc)
Without this change, users can not create a namespace in webhook envtest tests, for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see you removed
scheme := apimachineryruntime.NewScheme()
err = batchv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
So, now all coretypes are added by default, right?
To ensure clarity and make it easier to follow the changes, I think we should split this into separate PRs for each goal. This approach will help in maintaining a clear discussion for each change, simplify the release notes, and ensure each fix or change gets the attention it deserves.
Could you please open a PR for each fix/change proposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify: For example, in this case, we need to explain what has changed and why in the PR, and release notes so due that we cannot have many changes with diff purposes at the same PR
err = admissionv1.AddToScheme(scheme) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// +kubebuilder:scaffold:scheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catcher
Expect(err).NotTo(HaveOccurred()) | ||
Expect(k8sClient).NotTo(BeNil()) | ||
|
||
// start webhook server using Manager. | ||
webhookInstallOptions := &testEnv.WebhookInstallOptions | ||
mgr, err := ctrl.NewManager(cfg, ctrl.Options{ | ||
Scheme: scheme, | ||
Scheme: scheme.Scheme, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same motivation as this one #4441 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work 🥇 , but I think it would be beneficial to split these changes into separate PRs, each addressing a specific context. While the changes are relatively small, having focused PRs improves clarity and makes it easier to review and track changes.
I suggest organizing the changes as follows:
-
📖 Improve and fix the test information for tutorials
Focus on enhancing and correcting the tutorial content to provide clearer guidance for users. -
(go/v4): 🐛 Ensure that schemes are scaffolded before the envtest starts
Address the issue where schemes need to be properly registered before the test environment is initialized to avoid potential runtime errors. -
(go/v4): Standardize the webhook and controller test layout
Introduce a consistent layout for webhook and controller tests, aligning them with best practices for readability and maintainability.
Splitting these into distinct PRs will make each change easier to review and maintain. Let me know what you think!
By("bootstrapping test environment") | ||
testEnv = &envtest.Environment{ | ||
CRDInstallOptions: envtest.CRDInstallOptions{Scheme: scheme.Scheme}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this option was added?
I do not think that we need it by default?
Would that be required for ANY case scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is needed for webhook tests #4441 (comment)
I think only needed for webhook, but would add to both, for consistency
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. |
Scaffold
internal/controller/suite_test.go
andinternal/webhook/version/suite_test.go
have very similar code.This PR makes them more similar