@@ -31,7 +31,6 @@ import (
31
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
32
"k8s.io/apimachinery/pkg/runtime"
33
33
"k8s.io/apimachinery/pkg/runtime/schema"
34
- "k8s.io/apiserver/pkg/storage/names"
35
34
"k8s.io/client-go/kubernetes/scheme"
36
35
"k8s.io/client-go/tools/cache"
37
36
"k8s.io/kubernetes/test/e2e/framework/testfiles"
@@ -101,9 +100,9 @@ func visitManifests(cb func([]byte) error, files ...string) error {
101
100
return nil
102
101
}
103
102
104
- // PatchItems modifies the given items in place such that each
105
- // test gets its own instances, to avoid conflicts between different tests and
106
- // between tests and normal deployments.
103
+ // PatchItems modifies the given items in place such that each test
104
+ // gets its own instances, to avoid conflicts between different tests
105
+ // and between tests and normal deployments.
107
106
//
108
107
// This is done by:
109
108
// - creating namespaced items inside the test's namespace
@@ -288,27 +287,18 @@ var factories = map[What]ItemFactory{
288
287
{"StorageClass" }: & storageClassFactory {},
289
288
}
290
289
291
- // uniquifyName makes the name of some item unique per namespace by appending the
292
- // generated unique name of the test namespace .
293
- func (f * Framework ) uniquifyName (item * string ) {
290
+ // PatchName makes the name of some item unique by appending the
291
+ // generated unique name.
292
+ func (f * Framework ) PatchName (item * string ) {
294
293
if * item != "" {
295
294
* item = * item + "-" + f .UniqueName
296
295
}
297
296
}
298
297
299
- // randomizeStorageClassName makes the name of the storage class unique per call
300
- // by appending the generated unique name of the test namespace and a random 5
301
- // character string
302
- func (f * Framework ) randomizeStorageClassName (item * string ) {
303
- if * item != "" {
304
- * item = names .SimpleNameGenerator .GenerateName (* item + "-" + f .UniqueName + "-" )
305
- }
306
- }
307
-
308
- // patchNamespace moves the item into the test's namespace. Not
298
+ // PatchNamespace moves the item into the test's namespace. Not
309
299
// all items can be namespaced. For those, the name also needs to be
310
300
// patched.
311
- func (f * Framework ) patchNamespace (item * string ) {
301
+ func (f * Framework ) PatchNamespace (item * string ) {
312
302
if f .Namespace != nil {
313
303
* item = f .Namespace .GetName ()
314
304
}
@@ -317,31 +307,31 @@ func (f *Framework) patchNamespace(item *string) {
317
307
func (f * Framework ) patchItemRecursively (item interface {}) error {
318
308
switch item := item .(type ) {
319
309
case * rbac.Subject :
320
- f .patchNamespace (& item .Namespace )
310
+ f .PatchNamespace (& item .Namespace )
321
311
case * rbac.RoleRef :
322
312
// TODO: avoid hard-coding this special name. Perhaps add a Framework.PredefinedRoles
323
313
// which contains all role names that are defined cluster-wide before the test starts?
324
314
// All those names are excempt from renaming. That list could be populated by querying
325
315
// and get extended by tests.
326
316
if item .Name != "e2e-test-privileged-psp" {
327
- f .uniquifyName (& item .Name )
317
+ f .PatchName (& item .Name )
328
318
}
329
319
case * rbac.ClusterRole :
330
- f .uniquifyName (& item .Name )
320
+ f .PatchName (& item .Name )
331
321
case * rbac.Role :
332
- f .patchNamespace (& item .Namespace )
322
+ f .PatchNamespace (& item .Namespace )
333
323
// Roles are namespaced, but because for RoleRef above we don't
334
324
// know whether the referenced role is a ClusterRole or Role
335
325
// and therefore always renames, we have to do the same here.
336
- f .uniquifyName (& item .Name )
326
+ f .PatchName (& item .Name )
337
327
case * storage.StorageClass :
338
- f .randomizeStorageClassName (& item .Name )
328
+ f .PatchName (& item .Name )
339
329
case * v1.ServiceAccount :
340
- f .patchNamespace (& item .ObjectMeta .Namespace )
330
+ f .PatchNamespace (& item .ObjectMeta .Namespace )
341
331
case * v1.Secret :
342
- f .patchNamespace (& item .ObjectMeta .Namespace )
332
+ f .PatchNamespace (& item .ObjectMeta .Namespace )
343
333
case * rbac.ClusterRoleBinding :
344
- f .uniquifyName (& item .Name )
334
+ f .PatchName (& item .Name )
345
335
for i := range item .Subjects {
346
336
if err := f .patchItemRecursively (& item .Subjects [i ]); err != nil {
347
337
return errors .Wrapf (err , "%T" , f )
@@ -351,7 +341,7 @@ func (f *Framework) patchItemRecursively(item interface{}) error {
351
341
return errors .Wrapf (err , "%T" , f )
352
342
}
353
343
case * rbac.RoleBinding :
354
- f .patchNamespace (& item .Namespace )
344
+ f .PatchNamespace (& item .Namespace )
355
345
for i := range item .Subjects {
356
346
if err := f .patchItemRecursively (& item .Subjects [i ]); err != nil {
357
347
return errors .Wrapf (err , "%T" , f )
@@ -361,11 +351,11 @@ func (f *Framework) patchItemRecursively(item interface{}) error {
361
351
return errors .Wrapf (err , "%T" , f )
362
352
}
363
353
case * v1.Service :
364
- f .patchNamespace (& item .ObjectMeta .Namespace )
354
+ f .PatchNamespace (& item .ObjectMeta .Namespace )
365
355
case * apps.StatefulSet :
366
- f .patchNamespace (& item .ObjectMeta .Namespace )
356
+ f .PatchNamespace (& item .ObjectMeta .Namespace )
367
357
case * apps.DaemonSet :
368
- f .patchNamespace (& item .ObjectMeta .Namespace )
358
+ f .PatchNamespace (& item .ObjectMeta .Namespace )
369
359
default :
370
360
return errors .Errorf ("missing support for patching item of type %T" , item )
371
361
}
0 commit comments