From c59ee802c72a9918df021df7726903fca687436f Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Thu, 4 Apr 2024 16:55:44 +0100 Subject: [PATCH] Fix API conversion webhooks in the apivalidation tests API versions must be registered in the scheme before starting the envtest in order for conversion webhooks to be registered. --- .../apivalidations/openstackcluster_test.go | 1 - test/e2e/suites/apivalidations/suite_test.go | 29 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/test/e2e/suites/apivalidations/openstackcluster_test.go b/test/e2e/suites/apivalidations/openstackcluster_test.go index 6ef30c3461..d05a21c732 100644 --- a/test/e2e/suites/apivalidations/openstackcluster_test.go +++ b/test/e2e/suites/apivalidations/openstackcluster_test.go @@ -25,7 +25,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7" infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1" ) diff --git a/test/e2e/suites/apivalidations/suite_test.go b/test/e2e/suites/apivalidations/suite_test.go index 6705a96aa5..b042930e53 100644 --- a/test/e2e/suites/apivalidations/suite_test.go +++ b/test/e2e/suites/apivalidations/suite_test.go @@ -63,12 +63,21 @@ func TestAPIs(t *testing.T) { } var _ = BeforeSuite(func() { + testScheme = scheme.Scheme + for _, f := range []func(*runtime.Scheme) error{ + infrav1alpha1.AddToScheme, + infrav1alpha5.AddToScheme, + infrav1alpha6.AddToScheme, + infrav1alpha7.AddToScheme, + infrav1.AddToScheme, + } { + Expect(f(testScheme)).To(Succeed()) + } + By("bootstrapping test environment") + testCRDs := filepath.Join("..", "..", "..", "..", "config", "crd", "bases") testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{ - // NOTE: These are the bare CRDs without conversion webhooks - filepath.Join("..", "..", "..", "..", "config", "crd", "bases"), - }, + CRDDirectoryPaths: []string{testCRDs}, ErrorIfCRDPathMissing: true, WebhookInstallOptions: envtest.WebhookInstallOptions{ Paths: []string{ @@ -86,17 +95,6 @@ var _ = BeforeSuite(func() { return testEnv.Stop() }) - testScheme = scheme.Scheme - for _, f := range []func(*runtime.Scheme) error{ - infrav1alpha1.AddToScheme, - infrav1alpha5.AddToScheme, - infrav1alpha6.AddToScheme, - infrav1alpha7.AddToScheme, - infrav1.AddToScheme, - } { - Expect(f(testScheme)).To(Succeed()) - } - k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) @@ -128,6 +126,7 @@ var _ = BeforeSuite(func() { Host: testEnv.WebhookInstallOptions.LocalServingHost, CertDir: testEnv.WebhookInstallOptions.LocalServingCertDir, }), + Logger: GinkgoLogr, }) Expect(err).ToNot(HaveOccurred(), "Manager setup should succeed") Expect(webhooks.RegisterAllWithManager(mgr)).To(BeEmpty(), "Failed to register webhooks")