@@ -32,10 +32,13 @@ import (
32
32
"github.com/onsi/ginkgo/v2"
33
33
"github.com/pkg/errors"
34
34
admissionv1 "k8s.io/api/admissionregistration/v1"
35
+ appsv1 "k8s.io/api/apps/v1"
35
36
corev1 "k8s.io/api/core/v1"
37
+ rbacv1 "k8s.io/api/rbac/v1"
36
38
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
37
39
apierrors "k8s.io/apimachinery/pkg/api/errors"
38
40
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
41
+ "k8s.io/apimachinery/pkg/runtime"
39
42
kerrors "k8s.io/apimachinery/pkg/util/errors"
40
43
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
41
44
"k8s.io/apimachinery/pkg/util/wait"
@@ -114,19 +117,20 @@ func init() {
114
117
utilruntime .Must (admissionv1 .AddToScheme (scheme .Scheme ))
115
118
utilruntime .Must (runtimev1 .AddToScheme (scheme .Scheme ))
116
119
utilruntime .Must (ipamv1 .AddToScheme (scheme .Scheme ))
117
- utilruntime .Must (builder .AddTransitionV1Beta2ToScheme (scheme .Scheme ))
118
120
utilruntime .Must (addonsv1 .AddToScheme (scheme .Scheme ))
119
121
}
120
122
121
123
// RunInput is the input for Run.
122
124
type RunInput struct {
123
- M * testing.M
124
- ManagerUncachedObjs []client.Object
125
- ManagerCacheOptions cache.Options
126
- SetupIndexes func (ctx context.Context , mgr ctrl.Manager )
127
- SetupReconcilers func (ctx context.Context , mgr ctrl.Manager )
128
- SetupEnv func (e * Environment )
129
- MinK8sVersion string
125
+ M * testing.M
126
+ ManagerUncachedObjs []client.Object
127
+ ManagerCacheOptions cache.Options
128
+ SetupIndexes func (ctx context.Context , mgr ctrl.Manager )
129
+ SetupReconcilers func (ctx context.Context , mgr ctrl.Manager )
130
+ SetupEnv func (e * Environment )
131
+ MinK8sVersion string
132
+ AdditionalSchemeBuilder runtime.SchemeBuilder
133
+ AdditionalCRDDirectoryPaths []string
130
134
}
131
135
132
136
// Run executes the tests of the given testing.M in a test environment.
@@ -147,8 +151,28 @@ func Run(ctx context.Context, input RunInput) int {
147
151
return input .M .Run ()
148
152
}
149
153
154
+ // Calculate the scheme.
155
+ scheme := runtime .NewScheme ()
156
+ utilruntime .Must (appsv1 .AddToScheme (scheme ))
157
+ utilruntime .Must (corev1 .AddToScheme (scheme ))
158
+ utilruntime .Must (rbacv1 .AddToScheme (scheme ))
159
+
160
+ utilruntime .Must (addonsv1 .AddToScheme (scheme ))
161
+ utilruntime .Must (admissionv1 .AddToScheme (scheme ))
162
+ utilruntime .Must (admissionv1 .AddToScheme (scheme ))
163
+ utilruntime .Must (apiextensionsv1 .AddToScheme (scheme ))
164
+ utilruntime .Must (bootstrapv1 .AddToScheme (scheme ))
165
+ utilruntime .Must (clusterv1 .AddToScheme (scheme ))
166
+ utilruntime .Must (controlplanev1 .AddToScheme (scheme ))
167
+ utilruntime .Must (expv1 .AddToScheme (scheme ))
168
+ utilruntime .Must (ipamv1 .AddToScheme (scheme ))
169
+ utilruntime .Must (runtimev1 .AddToScheme (scheme ))
170
+ if input .AdditionalSchemeBuilder != nil {
171
+ utilruntime .Must (input .AdditionalSchemeBuilder .AddToScheme (scheme ))
172
+ }
173
+
150
174
// Bootstrapping test environment
151
- env := newEnvironment (input .ManagerCacheOptions , input .ManagerUncachedObjs ... )
175
+ env := newEnvironment (scheme , input . AdditionalCRDDirectoryPaths , input .ManagerCacheOptions , input .ManagerUncachedObjs ... )
152
176
153
177
ctx , cancel := context .WithCancelCause (ctx )
154
178
env .cancelManager = cancel
@@ -233,20 +257,24 @@ type Environment struct {
233
257
//
234
258
// This function should be called only once for each package you're running tests within,
235
259
// usually the environment is initialized in a suite_test.go file within a `BeforeSuite` ginkgo block.
236
- func newEnvironment (managerCacheOptions cache.Options , uncachedObjs ... client.Object ) * Environment {
260
+ func newEnvironment (scheme * runtime. Scheme , additionalCRDDirectoryPaths [] string , managerCacheOptions cache.Options , uncachedObjs ... client.Object ) * Environment {
237
261
// Get the root of the current file to use in CRD paths.
238
262
_ , filename , _ , _ := goruntime .Caller (0 ) //nolint:dogsled
239
263
root := path .Join (path .Dir (filename ), ".." , ".." , ".." )
240
264
265
+ crdDirectoryPaths := []string {
266
+ filepath .Join (root , "config" , "crd" , "bases" ),
267
+ filepath .Join (root , "controlplane" , "kubeadm" , "config" , "crd" , "bases" ),
268
+ filepath .Join (root , "bootstrap" , "kubeadm" , "config" , "crd" , "bases" ),
269
+ }
270
+ for _ , path := range additionalCRDDirectoryPaths {
271
+ crdDirectoryPaths = append (crdDirectoryPaths , filepath .Join (root , path ))
272
+ }
273
+
241
274
// Create the test environment.
242
275
env := & envtest.Environment {
243
276
ErrorIfCRDPathMissing : true ,
244
- CRDDirectoryPaths : []string {
245
- filepath .Join (root , "config" , "crd" , "bases" ),
246
- filepath .Join (root , "controlplane" , "kubeadm" , "config" , "crd" , "bases" ),
247
- filepath .Join (root , "bootstrap" , "kubeadm" , "config" , "crd" , "bases" ),
248
- filepath .Join (root , "util" , "test" , "builder" , "crd" ),
249
- },
277
+ CRDDirectoryPaths : crdDirectoryPaths ,
250
278
CRDs : []* apiextensionsv1.CustomResourceDefinition {
251
279
builder .GenericBootstrapConfigCRD .DeepCopy (),
252
280
builder .GenericBootstrapConfigTemplateCRD .DeepCopy (),
@@ -296,7 +324,7 @@ func newEnvironment(managerCacheOptions cache.Options, uncachedObjs ...client.Ob
296
324
Controller : config.Controller {
297
325
UsePriorityQueue : ptr.To [bool ](feature .Gates .Enabled (feature .PriorityQueue )),
298
326
},
299
- Scheme : scheme . Scheme ,
327
+ Scheme : scheme ,
300
328
Metrics : metricsserver.Options {
301
329
BindAddress : "0" ,
302
330
},
0 commit comments