Skip to content

Commit 086a86b

Browse files
authored
Merge pull request kubernetes#77525 from davidz627/fix/externalMulti
Make external driver name generation contain a more random suffix in case of double generation in the same framework context (twice in the same test)
2 parents 0ff81d0 + c50e7fd commit 086a86b

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

test/e2e/framework/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ go_library(
9292
"//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
9393
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
9494
"//staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library",
95+
"//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library",
9596
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
9697
"//staging/src/k8s.io/client-go/discovery:go_default_library",
9798
"//staging/src/k8s.io/client-go/discovery/cached/memory:go_default_library",

test/e2e/framework/create.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/runtime"
3333
"k8s.io/apimachinery/pkg/runtime/schema"
34+
"k8s.io/apiserver/pkg/storage/names"
3435
"k8s.io/client-go/kubernetes/scheme"
3536
"k8s.io/client-go/tools/cache"
3637
"k8s.io/kubernetes/test/e2e/framework/testfiles"
@@ -100,9 +101,9 @@ func visitManifests(cb func([]byte) error, files ...string) error {
100101
return nil
101102
}
102103

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.
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.
106107
//
107108
// This is done by:
108109
// - creating namespaced items inside the test's namespace
@@ -287,18 +288,27 @@ var factories = map[What]ItemFactory{
287288
{"StorageClass"}: &storageClassFactory{},
288289
}
289290

290-
// PatchName makes the name of some item unique by appending the
291-
// generated unique name.
292-
func (f *Framework) PatchName(item *string) {
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) {
293294
if *item != "" {
294295
*item = *item + "-" + f.UniqueName
295296
}
296297
}
297298

298-
// PatchNamespace moves the item into the test's namespace. Not
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
299309
// all items can be namespaced. For those, the name also needs to be
300310
// patched.
301-
func (f *Framework) PatchNamespace(item *string) {
311+
func (f *Framework) patchNamespace(item *string) {
302312
if f.Namespace != nil {
303313
*item = f.Namespace.GetName()
304314
}
@@ -307,31 +317,31 @@ func (f *Framework) PatchNamespace(item *string) {
307317
func (f *Framework) patchItemRecursively(item interface{}) error {
308318
switch item := item.(type) {
309319
case *rbac.Subject:
310-
f.PatchNamespace(&item.Namespace)
320+
f.patchNamespace(&item.Namespace)
311321
case *rbac.RoleRef:
312322
// TODO: avoid hard-coding this special name. Perhaps add a Framework.PredefinedRoles
313323
// which contains all role names that are defined cluster-wide before the test starts?
314324
// All those names are excempt from renaming. That list could be populated by querying
315325
// and get extended by tests.
316326
if item.Name != "e2e-test-privileged-psp" {
317-
f.PatchName(&item.Name)
327+
f.uniquifyName(&item.Name)
318328
}
319329
case *rbac.ClusterRole:
320-
f.PatchName(&item.Name)
330+
f.uniquifyName(&item.Name)
321331
case *rbac.Role:
322-
f.PatchNamespace(&item.Namespace)
332+
f.patchNamespace(&item.Namespace)
323333
// Roles are namespaced, but because for RoleRef above we don't
324334
// know whether the referenced role is a ClusterRole or Role
325335
// and therefore always renames, we have to do the same here.
326-
f.PatchName(&item.Name)
336+
f.uniquifyName(&item.Name)
327337
case *storage.StorageClass:
328-
f.PatchName(&item.Name)
338+
f.randomizeStorageClassName(&item.Name)
329339
case *v1.ServiceAccount:
330-
f.PatchNamespace(&item.ObjectMeta.Namespace)
340+
f.patchNamespace(&item.ObjectMeta.Namespace)
331341
case *v1.Secret:
332-
f.PatchNamespace(&item.ObjectMeta.Namespace)
342+
f.patchNamespace(&item.ObjectMeta.Namespace)
333343
case *rbac.ClusterRoleBinding:
334-
f.PatchName(&item.Name)
344+
f.uniquifyName(&item.Name)
335345
for i := range item.Subjects {
336346
if err := f.patchItemRecursively(&item.Subjects[i]); err != nil {
337347
return errors.Wrapf(err, "%T", f)
@@ -341,7 +351,7 @@ func (f *Framework) patchItemRecursively(item interface{}) error {
341351
return errors.Wrapf(err, "%T", f)
342352
}
343353
case *rbac.RoleBinding:
344-
f.PatchNamespace(&item.Namespace)
354+
f.patchNamespace(&item.Namespace)
345355
for i := range item.Subjects {
346356
if err := f.patchItemRecursively(&item.Subjects[i]); err != nil {
347357
return errors.Wrapf(err, "%T", f)
@@ -351,11 +361,11 @@ func (f *Framework) patchItemRecursively(item interface{}) error {
351361
return errors.Wrapf(err, "%T", f)
352362
}
353363
case *v1.Service:
354-
f.PatchNamespace(&item.ObjectMeta.Namespace)
364+
f.patchNamespace(&item.ObjectMeta.Namespace)
355365
case *apps.StatefulSet:
356-
f.PatchNamespace(&item.ObjectMeta.Namespace)
366+
f.patchNamespace(&item.ObjectMeta.Namespace)
357367
case *apps.DaemonSet:
358-
f.PatchNamespace(&item.ObjectMeta.Namespace)
368+
f.patchNamespace(&item.ObjectMeta.Namespace)
359369
default:
360370
return errors.Errorf("missing support for patching item of type %T", item)
361371
}

0 commit comments

Comments
 (0)