-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,7 @@ import ( | |
. "github.com/onsi/gomega" | ||
|
||
admissionv1 "k8s.io/api/admission/v1" | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. was this one not used? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see you removed
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 commentThe 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 commentThe 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 |
||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/rest" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
@@ -43,17 +39,20 @@ import ( | |
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
|
||
batchv1 "tutorial.kubebuilder.io/project/api/v1" | ||
// +kubebuilder:scaffold:imports | ||
) | ||
|
||
// These tests use Ginkgo (BDD-style Go testing framework). Refer to | ||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. | ||
|
||
var ( | ||
ctx context.Context | ||
cancel context.CancelFunc | ||
testEnv *envtest.Environment | ||
cfg *rest.Config | ||
ctx context.Context | ||
k8sClient client.Client | ||
testEnv *envtest.Environment | ||
) | ||
|
||
func TestAPIs(t *testing.T) { | ||
|
@@ -67,8 +66,18 @@ var _ = BeforeSuite(func() { | |
|
||
ctx, cancel = context.WithCancel(context.TODO()) | ||
|
||
var err error | ||
err = batchv1.AddToScheme(scheme.Scheme) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = admissionv1.AddToScheme(scheme.Scheme) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// +kubebuilder:scaffold:scheme | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Why this option was added? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, | ||
ErrorIfCRDPathMissing: false, | ||
|
||
|
@@ -82,29 +91,19 @@ var _ = BeforeSuite(func() { | |
testEnv.BinaryAssetsDirectory = getFirstFoundEnvTestBinaryDir() | ||
} | ||
|
||
var err error | ||
// cfg is defined in this file globally. | ||
cfg, err = testEnv.Start() | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(cfg).NotTo(BeNil()) | ||
|
||
scheme := apimachineryruntime.NewScheme() | ||
err = batchv1.AddToScheme(scheme) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = admissionv1.AddToScheme(scheme) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// +kubebuilder:scaffold:scheme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catcher |
||
|
||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) | ||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) | ||
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, | ||
WebhookServer: webhook.NewServer(webhook.Options{ | ||
Host: webhookInstallOptions.LocalServingHost, | ||
Port: webhookInstallOptions.LocalServingPort, | ||
|
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