From f051464ef67d2dd3d81678219252c632bfa523d9 Mon Sep 17 00:00:00 2001 From: Mateus Oliveira Date: Thu, 2 Jan 2025 03:02:42 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(go/v4)=20ensure=20that=20schema?= =?UTF-8?q?s=20are=20added=20before=20start=20EnvTest-based=20suite=20test?= =?UTF-8?q?s=20for=20webhooks=20and=20controllers=20(#4466)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: add schemas prior to envtest start Signed-off-by: Mateus Oliveira --- .../project/internal/controller/suite_test.go | 28 +++++++++---------- .../internal/webhook/v1/webhook_suite_test.go | 20 ++++++------- .../project/internal/controller/suite_test.go | 12 ++++---- .../project/internal/controller/suite_test.go | 28 +++++++++---------- .../internal/webhook/v1/webhook_suite_test.go | 20 ++++++------- .../internal/webhook/v2/webhook_suite_test.go | 20 ++++++------- .../cronjob-tutorial/generate_cronjob.go | 23 ++++++++------- .../cronjob-tutorial/writing_tests_env.go | 12 ++++---- .../controllers/controller_suitetest.go | 6 ++-- .../templates/webhooks/webhook_suitetest.go | 20 ++++++------- .../internal/controller/apps/suite_test.go | 12 ++++---- .../controller/cert-manager/suite_test.go | 12 ++++---- .../internal/controller/crew/suite_test.go | 12 ++++---- .../controller/example.com/suite_test.go | 18 ++++++------ .../internal/controller/fiz/suite_test.go | 12 ++++---- .../controller/foo.policy/suite_test.go | 12 ++++---- .../internal/controller/foo/suite_test.go | 12 ++++---- .../controller/sea-creatures/suite_test.go | 18 ++++++------ .../internal/controller/ship/suite_test.go | 24 ++++++++-------- .../webhook/apps/v1/webhook_suite_test.go | 20 ++++++------- .../cert-manager/v1/webhook_suite_test.go | 20 ++++++------- .../webhook/core/v1/webhook_suite_test.go | 20 ++++++------- .../webhook/crew/v1/webhook_suite_test.go | 20 ++++++------- .../v1alpha1/webhook_suite_test.go | 20 ++++++------- .../webhook/ship/v1/webhook_suite_test.go | 20 ++++++------- .../ship/v2alpha1/webhook_suite_test.go | 20 ++++++------- .../internal/controller/suite_test.go | 18 ++++++------ .../webhook/v1alpha1/webhook_suite_test.go | 20 ++++++------- .../internal/controller/suite_test.go | 18 ++++++------ .../internal/webhook/v1/webhook_suite_test.go | 20 ++++++------- 30 files changed, 270 insertions(+), 267 deletions(-) diff --git a/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go b/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go index 37def9c6e74..6228c33d70d 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go @@ -74,6 +74,20 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + /* + The CronJob Kind is added to the runtime scheme used by the test environment. + This ensures that the CronJob API is registered with the scheme, allowing the test controller to recognize and interact with CronJob resources. + */ + err = batchv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + /* + After the schemas, you will see the following marker. + This marker is what allows new schemas to be added here automatically when a new API is added to the project. + */ + + // +kubebuilder:scaffold:scheme + /* The envtest environment is configured to load Custom Resource Definitions (CRDs) from the specified directory. This setup enables the test environment to recognize and interact with the custom resources defined by these CRDs. @@ -92,25 +106,11 @@ var _ = BeforeSuite(func() { Then, we start the envtest cluster. */ - var err error // cfg is defined in this file globally. cfg, err = testEnv.Start() Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - /* - The CronJob Kind is added to the runtime scheme used by the test environment. - This ensures that the CronJob API is registered with the scheme, allowing the test controller to recognize and interact with CronJob resources. - */ - err = batchv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - /* - After the schemas, you will see the following marker. - This marker is what allows new schemas to be added here automatically when a new API is added to the project. - */ - - // +kubebuilder:scaffold:scheme - /* A client is created for our test CRUD operations. */ diff --git a/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go b/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go index bc9b009658a..2f49aa1a62b 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = batchv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/docs/book/src/getting-started/testdata/project/internal/controller/suite_test.go b/docs/book/src/getting-started/testdata/project/internal/controller/suite_test.go index be07049d4f9..d97f2ecae76 100644 --- a/docs/book/src/getting-started/testdata/project/internal/controller/suite_test.go +++ b/docs/book/src/getting-started/testdata/project/internal/controller/suite_test.go @@ -58,6 +58,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = cachev1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, @@ -69,17 +75,11 @@ 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()) - err = cachev1alpha1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/suite_test.go b/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/suite_test.go index 37def9c6e74..6228c33d70d 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/suite_test.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/suite_test.go @@ -74,6 +74,20 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + /* + The CronJob Kind is added to the runtime scheme used by the test environment. + This ensures that the CronJob API is registered with the scheme, allowing the test controller to recognize and interact with CronJob resources. + */ + err = batchv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + /* + After the schemas, you will see the following marker. + This marker is what allows new schemas to be added here automatically when a new API is added to the project. + */ + + // +kubebuilder:scaffold:scheme + /* The envtest environment is configured to load Custom Resource Definitions (CRDs) from the specified directory. This setup enables the test environment to recognize and interact with the custom resources defined by these CRDs. @@ -92,25 +106,11 @@ var _ = BeforeSuite(func() { Then, we start the envtest cluster. */ - var err error // cfg is defined in this file globally. cfg, err = testEnv.Start() Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - /* - The CronJob Kind is added to the runtime scheme used by the test environment. - This ensures that the CronJob API is registered with the scheme, allowing the test controller to recognize and interact with CronJob resources. - */ - err = batchv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - /* - After the schemas, you will see the following marker. - This marker is what allows new schemas to be added here automatically when a new API is added to the project. - */ - - // +kubebuilder:scaffold:scheme - /* A client is created for our test CRUD operations. */ diff --git a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go index bc9b009658a..2f49aa1a62b 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = batchv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/webhook_suite_test.go b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/webhook_suite_test.go index df10d2ed863..04453d60c48 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/webhook_suite_test.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = batchv2.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = batchv2.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/hack/docs/internal/cronjob-tutorial/generate_cronjob.go b/hack/docs/internal/cronjob-tutorial/generate_cronjob.go index ac9c52377bc..d8d53e52082 100644 --- a/hack/docs/internal/cronjob-tutorial/generate_cronjob.go +++ b/hack/docs/internal/cronjob-tutorial/generate_cronjob.go @@ -540,11 +540,15 @@ var ( `, suiteTestEnv) hackutils.CheckError("updating suite_test.go to add more variables", err) - err = pluginutil.InsertCode( + err = pluginutil.ReplaceInFile( filepath.Join(sp.ctx.Dir, "internal/controller/suite_test.go"), - `ctx, cancel = context.WithCancel(context.TODO()) -`, suiteTestReadCRD) - hackutils.CheckError("updating suite_test.go to add text about CRD", err) + ` + err = batchv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme +`, suiteTestAddSchema) + hackutils.CheckError("updating suite_test.go to add schema", err) err = pluginutil.InsertCode( filepath.Join(sp.ctx.Dir, "internal/controller/suite_test.go"), @@ -555,15 +559,14 @@ var ( */`) hackutils.CheckError("updating suite_test.go to add text to show where envtest cluster start", err) - err = pluginutil.ReplaceInFile( + err = pluginutil.InsertCode( filepath.Join(sp.ctx.Dir, "internal/controller/suite_test.go"), ` - err = batchv1.AddToScheme(scheme.Scheme) + cfg, err = testEnv.Start() Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme -`, suiteTestAddSchema) - hackutils.CheckError("updating suite_test.go to add schema", err) + Expect(cfg).NotTo(BeNil()) +`, suiteTestClient) + hackutils.CheckError("updating suite_test.go to add text about test client", err) err = pluginutil.InsertCode( filepath.Join(sp.ctx.Dir, "internal/controller/suite_test.go"), diff --git a/hack/docs/internal/cronjob-tutorial/writing_tests_env.go b/hack/docs/internal/cronjob-tutorial/writing_tests_env.go index a5a6c669b3f..44cfb0c0cb0 100644 --- a/hack/docs/internal/cronjob-tutorial/writing_tests_env.go +++ b/hack/docs/internal/cronjob-tutorial/writing_tests_env.go @@ -43,12 +43,6 @@ var ( ) ` -const suiteTestReadCRD = ` - /* - The envtest environment is configured to load Custom Resource Definitions (CRDs) from the specified directory. - This setup enables the test environment to recognize and interact with the custom resources defined by these CRDs. - */` - const suiteTestAddSchema = ` /* The CronJob Kind is added to the runtime scheme used by the test environment. @@ -63,6 +57,12 @@ const suiteTestAddSchema = ` // +kubebuilder:scaffold:scheme + /* + The envtest environment is configured to load Custom Resource Definitions (CRDs) from the specified directory. + This setup enables the test environment to recognize and interact with the custom resources defined by these CRDs. + */` + +const suiteTestClient = ` /* A client is created for our test CRUD operations. */` diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go index b64a7eff591..fee33683adc 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go @@ -171,6 +171,9 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + %s + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join({{ .CRDDirectoryRelativePath }}, "config", "crd", "bases")}, @@ -182,14 +185,11 @@ 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()) - %s - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go index 33ac552a165..ff232a97a3b 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go @@ -230,6 +230,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = %s.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = %s.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + %s + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join({{ .BaseDirectoryRelativePath }}, "config", "crd", "bases")}, @@ -245,21 +255,11 @@ 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 = %s.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = %s.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - %s - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/apps/suite_test.go b/testdata/project-v4-multigroup/internal/controller/apps/suite_test.go index fead8802d20..ff0f7185577 100644 --- a/testdata/project-v4-multigroup/internal/controller/apps/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/apps/suite_test.go @@ -57,6 +57,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = appsv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -68,17 +74,11 @@ 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()) - err = appsv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/cert-manager/suite_test.go b/testdata/project-v4-multigroup/internal/controller/cert-manager/suite_test.go index 78961d63ea6..321b9c57d6d 100644 --- a/testdata/project-v4-multigroup/internal/controller/cert-manager/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/cert-manager/suite_test.go @@ -57,6 +57,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = certmanagerv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -68,17 +74,11 @@ 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()) - err = certmanagerv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/crew/suite_test.go b/testdata/project-v4-multigroup/internal/controller/crew/suite_test.go index a066d769c03..75cc83279b9 100644 --- a/testdata/project-v4-multigroup/internal/controller/crew/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/crew/suite_test.go @@ -58,6 +58,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = crewv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -69,17 +75,11 @@ 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()) - err = crewv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/example.com/suite_test.go b/testdata/project-v4-multigroup/internal/controller/example.com/suite_test.go index cb519a13464..88d63dd8d71 100644 --- a/testdata/project-v4-multigroup/internal/controller/example.com/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/example.com/suite_test.go @@ -59,6 +59,15 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = examplecomv1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = examplecomv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -70,20 +79,11 @@ 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()) - err = examplecomv1alpha1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - err = examplecomv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go b/testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go index 50665bd8fbd..dac842b933e 100644 --- a/testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go @@ -58,6 +58,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = fizv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -69,17 +75,11 @@ 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()) - err = fizv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go b/testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go index 4575197ac61..cd3b052d5d8 100644 --- a/testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go @@ -58,6 +58,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = foopolicyv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -69,17 +75,11 @@ 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()) - err = foopolicyv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/foo/suite_test.go b/testdata/project-v4-multigroup/internal/controller/foo/suite_test.go index 4825eca585e..57ac8758cd7 100644 --- a/testdata/project-v4-multigroup/internal/controller/foo/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/foo/suite_test.go @@ -58,6 +58,12 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = foov1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -69,17 +75,11 @@ 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()) - err = foov1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go b/testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go index 46a27004878..8d6d10e3217 100644 --- a/testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go @@ -59,6 +59,15 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = seacreaturesv1beta1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = seacreaturesv1beta2.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -70,20 +79,11 @@ 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()) - err = seacreaturesv1beta1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - err = seacreaturesv1beta2.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/controller/ship/suite_test.go b/testdata/project-v4-multigroup/internal/controller/ship/suite_test.go index 6de72408caa..ac51916a1a4 100644 --- a/testdata/project-v4-multigroup/internal/controller/ship/suite_test.go +++ b/testdata/project-v4-multigroup/internal/controller/ship/suite_test.go @@ -60,6 +60,18 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = shipv1beta1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = shipv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = shipv2alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -71,23 +83,11 @@ 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()) - err = shipv1beta1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - err = shipv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - err = shipv2alpha1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/apps/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/apps/v1/webhook_suite_test.go index 9be1e456da7..2228b1700fe 100644 --- a/testdata/project-v4-multigroup/internal/webhook/apps/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/apps/v1/webhook_suite_test.go @@ -65,6 +65,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = appsv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -80,21 +90,11 @@ 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 = appsv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/webhook_suite_test.go index af31971709a..828e45fc132 100644 --- a/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/webhook_suite_test.go @@ -65,6 +65,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = certmanagerv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -80,21 +90,11 @@ 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 = certmanagerv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/core/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/core/v1/webhook_suite_test.go index 602a7ddfadc..0783acbb5c5 100644 --- a/testdata/project-v4-multigroup/internal/webhook/core/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/core/v1/webhook_suite_test.go @@ -65,6 +65,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = corev1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -80,21 +90,11 @@ 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 = corev1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/crew/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/crew/v1/webhook_suite_test.go index 2384e67835f..9552f2ed486 100644 --- a/testdata/project-v4-multigroup/internal/webhook/crew/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/crew/v1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = crewv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = crewv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/webhook_suite_test.go index 5f0c1dcd441..18fd8776ae5 100644 --- a/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = examplecomv1alpha1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = examplecomv1alpha1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/ship/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/ship/v1/webhook_suite_test.go index 43bb2d7e4a5..637f650c7f9 100644 --- a/testdata/project-v4-multigroup/internal/webhook/ship/v1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/ship/v1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = shipv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = shipv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/webhook_suite_test.go b/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/webhook_suite_test.go index 525e0e5596c..b39099faf74 100644 --- a/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/webhook_suite_test.go +++ b/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = shipv2alpha1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = shipv2alpha1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-with-plugins/internal/controller/suite_test.go b/testdata/project-v4-with-plugins/internal/controller/suite_test.go index 801ead7e07c..2d3582f7cfc 100644 --- a/testdata/project-v4-with-plugins/internal/controller/suite_test.go +++ b/testdata/project-v4-with-plugins/internal/controller/suite_test.go @@ -59,6 +59,15 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = examplecomv1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = examplecomv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, @@ -70,20 +79,11 @@ 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()) - err = examplecomv1alpha1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - err = examplecomv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/webhook_suite_test.go b/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/webhook_suite_test.go index c8ef66a3a75..c1dda2b48d2 100644 --- a/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/webhook_suite_test.go +++ b/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = examplecomv1alpha1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = examplecomv1alpha1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4/internal/controller/suite_test.go b/testdata/project-v4/internal/controller/suite_test.go index b87af70f316..1b240307f4d 100644 --- a/testdata/project-v4/internal/controller/suite_test.go +++ b/testdata/project-v4/internal/controller/suite_test.go @@ -60,6 +60,15 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + err = crewv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + err = certmanagerv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, @@ -71,20 +80,11 @@ 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()) - err = crewv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - err = certmanagerv1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) diff --git a/testdata/project-v4/internal/webhook/v1/webhook_suite_test.go b/testdata/project-v4/internal/webhook/v1/webhook_suite_test.go index 786dcd59c35..0eb9fee6c72 100644 --- a/testdata/project-v4/internal/webhook/v1/webhook_suite_test.go +++ b/testdata/project-v4/internal/webhook/v1/webhook_suite_test.go @@ -66,6 +66,16 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + var err error + scheme := apimachineryruntime.NewScheme() + err = crewv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + err = admissionv1.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, @@ -81,21 +91,11 @@ 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 = crewv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - err = admissionv1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) - - // +kubebuilder:scaffold:scheme - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil())