Revert "Make external driver storage class name generation contain a more random suffix in case of double generation in the same framework context (twice in the same test)"

This reverts commit c50e7fd301 because
it included API changes that shouldn't have been in that PR and
fixing the storage class conflict inside the framework is probably the
wrong place.
This commit is contained in:
Patrick Ohly 2019-05-08 17:28:13 +02:00
parent 086a86b9e2
commit 62c5c6345e
2 changed files with 21 additions and 32 deletions

View File

@ -92,7 +92,6 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library", "//staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/client-go/discovery:go_default_library", "//staging/src/k8s.io/client-go/discovery:go_default_library",
"//staging/src/k8s.io/client-go/discovery/cached/memory:go_default_library", "//staging/src/k8s.io/client-go/discovery/cached/memory:go_default_library",

View File

@ -31,7 +31,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/test/e2e/framework/testfiles" "k8s.io/kubernetes/test/e2e/framework/testfiles"
@ -101,9 +100,9 @@ func visitManifests(cb func([]byte) error, files ...string) error {
return nil return nil
} }
// PatchItems modifies the given items in place such that each // PatchItems modifies the given items in place such that each test
// test gets its own instances, to avoid conflicts between different tests and // gets its own instances, to avoid conflicts between different tests
// between tests and normal deployments. // and between tests and normal deployments.
// //
// This is done by: // This is done by:
// - creating namespaced items inside the test's namespace // - creating namespaced items inside the test's namespace
@ -288,27 +287,18 @@ var factories = map[What]ItemFactory{
{"StorageClass"}: &storageClassFactory{}, {"StorageClass"}: &storageClassFactory{},
} }
// uniquifyName makes the name of some item unique per namespace by appending the // PatchName makes the name of some item unique by appending the
// generated unique name of the test namespace. // generated unique name.
func (f *Framework) uniquifyName(item *string) { func (f *Framework) PatchName(item *string) {
if *item != "" { if *item != "" {
*item = *item + "-" + f.UniqueName *item = *item + "-" + f.UniqueName
} }
} }
// randomizeStorageClassName makes the name of the storage class unique per call // PatchNamespace moves the item into the test's namespace. Not
// by appending the generated unique name of the test namespace and a random 5
// character string
func (f *Framework) randomizeStorageClassName(item *string) {
if *item != "" {
*item = names.SimpleNameGenerator.GenerateName(*item + "-" + f.UniqueName + "-")
}
}
// patchNamespace moves the item into the test's namespace. Not
// all items can be namespaced. For those, the name also needs to be // all items can be namespaced. For those, the name also needs to be
// patched. // patched.
func (f *Framework) patchNamespace(item *string) { func (f *Framework) PatchNamespace(item *string) {
if f.Namespace != nil { if f.Namespace != nil {
*item = f.Namespace.GetName() *item = f.Namespace.GetName()
} }
@ -317,31 +307,31 @@ func (f *Framework) patchNamespace(item *string) {
func (f *Framework) patchItemRecursively(item interface{}) error { func (f *Framework) patchItemRecursively(item interface{}) error {
switch item := item.(type) { switch item := item.(type) {
case *rbac.Subject: case *rbac.Subject:
f.patchNamespace(&item.Namespace) f.PatchNamespace(&item.Namespace)
case *rbac.RoleRef: case *rbac.RoleRef:
// TODO: avoid hard-coding this special name. Perhaps add a Framework.PredefinedRoles // TODO: avoid hard-coding this special name. Perhaps add a Framework.PredefinedRoles
// which contains all role names that are defined cluster-wide before the test starts? // which contains all role names that are defined cluster-wide before the test starts?
// All those names are excempt from renaming. That list could be populated by querying // All those names are excempt from renaming. That list could be populated by querying
// and get extended by tests. // and get extended by tests.
if item.Name != "e2e-test-privileged-psp" { if item.Name != "e2e-test-privileged-psp" {
f.uniquifyName(&item.Name) f.PatchName(&item.Name)
} }
case *rbac.ClusterRole: case *rbac.ClusterRole:
f.uniquifyName(&item.Name) f.PatchName(&item.Name)
case *rbac.Role: case *rbac.Role:
f.patchNamespace(&item.Namespace) f.PatchNamespace(&item.Namespace)
// Roles are namespaced, but because for RoleRef above we don't // Roles are namespaced, but because for RoleRef above we don't
// know whether the referenced role is a ClusterRole or Role // know whether the referenced role is a ClusterRole or Role
// and therefore always renames, we have to do the same here. // and therefore always renames, we have to do the same here.
f.uniquifyName(&item.Name) f.PatchName(&item.Name)
case *storage.StorageClass: case *storage.StorageClass:
f.randomizeStorageClassName(&item.Name) f.PatchName(&item.Name)
case *v1.ServiceAccount: case *v1.ServiceAccount:
f.patchNamespace(&item.ObjectMeta.Namespace) f.PatchNamespace(&item.ObjectMeta.Namespace)
case *v1.Secret: case *v1.Secret:
f.patchNamespace(&item.ObjectMeta.Namespace) f.PatchNamespace(&item.ObjectMeta.Namespace)
case *rbac.ClusterRoleBinding: case *rbac.ClusterRoleBinding:
f.uniquifyName(&item.Name) f.PatchName(&item.Name)
for i := range item.Subjects { for i := range item.Subjects {
if err := f.patchItemRecursively(&item.Subjects[i]); err != nil { if err := f.patchItemRecursively(&item.Subjects[i]); err != nil {
return errors.Wrapf(err, "%T", f) return errors.Wrapf(err, "%T", f)
@ -351,7 +341,7 @@ func (f *Framework) patchItemRecursively(item interface{}) error {
return errors.Wrapf(err, "%T", f) return errors.Wrapf(err, "%T", f)
} }
case *rbac.RoleBinding: case *rbac.RoleBinding:
f.patchNamespace(&item.Namespace) f.PatchNamespace(&item.Namespace)
for i := range item.Subjects { for i := range item.Subjects {
if err := f.patchItemRecursively(&item.Subjects[i]); err != nil { if err := f.patchItemRecursively(&item.Subjects[i]); err != nil {
return errors.Wrapf(err, "%T", f) return errors.Wrapf(err, "%T", f)
@ -361,11 +351,11 @@ func (f *Framework) patchItemRecursively(item interface{}) error {
return errors.Wrapf(err, "%T", f) return errors.Wrapf(err, "%T", f)
} }
case *v1.Service: case *v1.Service:
f.patchNamespace(&item.ObjectMeta.Namespace) f.PatchNamespace(&item.ObjectMeta.Namespace)
case *apps.StatefulSet: case *apps.StatefulSet:
f.patchNamespace(&item.ObjectMeta.Namespace) f.PatchNamespace(&item.ObjectMeta.Namespace)
case *apps.DaemonSet: case *apps.DaemonSet:
f.patchNamespace(&item.ObjectMeta.Namespace) f.PatchNamespace(&item.ObjectMeta.Namespace)
default: default:
return errors.Errorf("missing support for patching item of type %T", item) return errors.Errorf("missing support for patching item of type %T", item)
} }