Skip to content

Commit c59ee80

Browse files
committed
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.
1 parent 038c11f commit c59ee80

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

test/e2e/suites/apivalidations/openstackcluster_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727

28-
"sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
2928
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
3029
)
3130

test/e2e/suites/apivalidations/suite_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,21 @@ func TestAPIs(t *testing.T) {
6363
}
6464

6565
var _ = BeforeSuite(func() {
66+
testScheme = scheme.Scheme
67+
for _, f := range []func(*runtime.Scheme) error{
68+
infrav1alpha1.AddToScheme,
69+
infrav1alpha5.AddToScheme,
70+
infrav1alpha6.AddToScheme,
71+
infrav1alpha7.AddToScheme,
72+
infrav1.AddToScheme,
73+
} {
74+
Expect(f(testScheme)).To(Succeed())
75+
}
76+
6677
By("bootstrapping test environment")
78+
testCRDs := filepath.Join("..", "..", "..", "..", "config", "crd", "bases")
6779
testEnv = &envtest.Environment{
68-
CRDDirectoryPaths: []string{
69-
// NOTE: These are the bare CRDs without conversion webhooks
70-
filepath.Join("..", "..", "..", "..", "config", "crd", "bases"),
71-
},
80+
CRDDirectoryPaths: []string{testCRDs},
7281
ErrorIfCRDPathMissing: true,
7382
WebhookInstallOptions: envtest.WebhookInstallOptions{
7483
Paths: []string{
@@ -86,17 +95,6 @@ var _ = BeforeSuite(func() {
8695
return testEnv.Stop()
8796
})
8897

89-
testScheme = scheme.Scheme
90-
for _, f := range []func(*runtime.Scheme) error{
91-
infrav1alpha1.AddToScheme,
92-
infrav1alpha5.AddToScheme,
93-
infrav1alpha6.AddToScheme,
94-
infrav1alpha7.AddToScheme,
95-
infrav1.AddToScheme,
96-
} {
97-
Expect(f(testScheme)).To(Succeed())
98-
}
99-
10098
k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme})
10199
Expect(err).NotTo(HaveOccurred())
102100
Expect(k8sClient).NotTo(BeNil())
@@ -128,6 +126,7 @@ var _ = BeforeSuite(func() {
128126
Host: testEnv.WebhookInstallOptions.LocalServingHost,
129127
CertDir: testEnv.WebhookInstallOptions.LocalServingCertDir,
130128
}),
129+
Logger: GinkgoLogr,
131130
})
132131
Expect(err).ToNot(HaveOccurred(), "Manager setup should succeed")
133132
Expect(webhooks.RegisterAllWithManager(mgr)).To(BeEmpty(), "Failed to register webhooks")

0 commit comments

Comments
 (0)