Skip to content

Commit

Permalink
Fix API conversion webhooks in the apivalidation tests
Browse files Browse the repository at this point in the history
API versions must be registered in the scheme before starting the
envtest in order for conversion webhooks to be registered.
  • Loading branch information
mdbooth committed Apr 4, 2024
1 parent 038c11f commit c59ee80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion test/e2e/suites/apivalidations/openstackcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
29 changes: 14 additions & 15 deletions test/e2e/suites/apivalidations/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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())
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c59ee80

Please sign in to comment.