e2e storage: eliminate explicit test driver cleanup

Cleanup can be handled inside the setup code with ginkgo.DeferCleanup. This
simplifies the code.
This commit is contained in:
Patrick Ohly
2022-10-07 18:02:53 +02:00
parent 83415e5c9e
commit d8d3dc9476
24 changed files with 125 additions and 187 deletions

View File

@@ -157,7 +157,7 @@ func (n *nfsDriver) GetDynamicProvisionStorageClass(config *storageframework.Per
return storageframework.GetStorageClass(provisioner, parameters, nil, ns)
}
func (n *nfsDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (n *nfsDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
cs := f.ClientSet
ns := f.Namespace
n.externalPluginName = fmt.Sprintf("example.com/nfs-%s", ns.Name)
@@ -167,6 +167,10 @@ func (n *nfsDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTe
err := e2eauth.BindClusterRole(cs.RbacV1(), "cluster-admin", ns.Name,
rbacv1.Subject{Kind: rbacv1.ServiceAccountKind, Namespace: ns.Name, Name: "default"})
framework.ExpectNoError(err)
ginkgo.DeferCleanup(func(ctx context.Context) {
clusterRoleBindingName := ns.Name + "--" + "cluster-admin"
cs.RbacV1().ClusterRoleBindings().Delete(ctx, clusterRoleBindingName, *metav1.NewDeleteOptions(0))
})
err = e2eauth.WaitForAuthorizationUpdate(cs.AuthorizationV1(),
serviceaccount.MakeUsername(ns.Name, "default"),
@@ -175,16 +179,15 @@ func (n *nfsDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTe
ginkgo.By("creating an external dynamic provisioner pod")
n.externalProvisionerPod = utils.StartExternalProvisioner(cs, ns.Name, n.externalPluginName)
ginkgo.DeferCleanup(func() {
framework.ExpectNoError(e2epod.DeletePodWithWait(cs, n.externalProvisionerPod))
})
return &storageframework.PerTestConfig{
Driver: n,
Prefix: "nfs",
Framework: f,
}, func() {
framework.ExpectNoError(e2epod.DeletePodWithWait(cs, n.externalProvisionerPod))
clusterRoleBindingName := ns.Name + "--" + "cluster-admin"
cs.RbacV1().ClusterRoleBindings().Delete(context.TODO(), clusterRoleBindingName, *metav1.NewDeleteOptions(0))
}
Driver: n,
Prefix: "nfs",
Framework: f,
}
}
func (n *nfsDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -307,12 +310,12 @@ func (i *iSCSIDriver) GetPersistentVolumeSource(readOnly bool, fsType string, e2
return &pvSource, nil
}
func (i *iSCSIDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (i *iSCSIDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: i,
Prefix: "iscsi",
Framework: f,
}, func() {}
}
}
func (i *iSCSIDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -500,12 +503,12 @@ func (r *rbdDriver) GetPersistentVolumeSource(readOnly bool, fsType string, e2ev
return &pvSource, nil
}
func (r *rbdDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (r *rbdDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: r,
Prefix: "rbd",
Framework: f,
}, func() {}
}
}
func (r *rbdDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -614,12 +617,12 @@ func (c *cephFSDriver) GetPersistentVolumeSource(readOnly bool, fsType string, e
}, nil
}
func (c *cephFSDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (c *cephFSDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: c,
Prefix: "cephfs",
Framework: f,
}, func() {}
}
}
func (c *cephFSDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -690,12 +693,12 @@ func (h *hostPathDriver) GetVolumeSource(readOnly bool, fsType string, e2evolume
}
}
func (h *hostPathDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (h *hostPathDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: h,
Prefix: "hostpath",
Framework: f,
}, func() {}
}
}
func (h *hostPathDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -770,12 +773,12 @@ func (h *hostPathSymlinkDriver) GetVolumeSource(readOnly bool, fsType string, e2
}
}
func (h *hostPathSymlinkDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (h *hostPathSymlinkDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: h,
Prefix: "hostpathsymlink",
Framework: f,
}, func() {}
}
}
func (h *hostPathSymlinkDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -911,12 +914,12 @@ func (e *emptydirDriver) CreateVolume(config *storageframework.PerTestConfig, vo
return nil
}
func (e *emptydirDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (e *emptydirDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: e,
Prefix: "emptydir",
Framework: f,
}, func() {}
}
}
// GCE
@@ -1062,7 +1065,7 @@ func (g *gcePdDriver) GetDynamicProvisionStorageClass(config *storageframework.P
return storageframework.GetStorageClass(provisioner, parameters, &delayedBinding, ns)
}
func (g *gcePdDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (g *gcePdDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
config := &storageframework.PerTestConfig{
Driver: g,
Prefix: "gcepd",
@@ -1076,7 +1079,7 @@ func (g *gcePdDriver) PrepareTest(f *framework.Framework) (*storageframework.Per
},
}
}
return config, func() {}
return config
}
@@ -1209,21 +1212,22 @@ func (v *vSphereDriver) GetDynamicProvisionStorageClass(config *storageframework
return storageframework.GetStorageClass(provisioner, parameters, nil, ns)
}
func (v *vSphereDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
return &storageframework.PerTestConfig{
Driver: v,
Prefix: "vsphere",
Framework: f,
}, func() {
// Driver Cleanup function
// Logout each vSphere client connection to prevent session leakage
nodes := vspheretest.GetReadySchedulableNodeInfos()
for _, node := range nodes {
if node.VSphere.Client != nil {
node.VSphere.Client.Logout(context.TODO())
}
func (v *vSphereDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
ginkgo.DeferCleanup(func() {
// Driver Cleanup function
// Logout each vSphere client connection to prevent session leakage
nodes := vspheretest.GetReadySchedulableNodeInfos()
for _, node := range nodes {
if node.VSphere.Client != nil {
node.VSphere.Client.Logout(context.TODO())
}
}
})
return &storageframework.PerTestConfig{
Driver: v,
Prefix: "vsphere",
Framework: f,
}
}
func (v *vSphereDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -1354,12 +1358,12 @@ func (a *azureDiskDriver) GetDynamicProvisionStorageClass(config *storageframewo
return storageframework.GetStorageClass(provisioner, parameters, &delayedBinding, ns)
}
func (a *azureDiskDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (a *azureDiskDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: a,
Prefix: "azure",
Framework: f,
}, func() {}
}
}
func (a *azureDiskDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -1492,7 +1496,7 @@ func (a *awsDriver) GetDynamicProvisionStorageClass(config *storageframework.Per
return storageframework.GetStorageClass(provisioner, parameters, &delayedBinding, ns)
}
func (a *awsDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (a *awsDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
config := &storageframework.PerTestConfig{
Driver: a,
Prefix: "aws",
@@ -1506,7 +1510,7 @@ func (a *awsDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTe
},
}
}
return config, func() {}
return config
}
func (a *awsDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -1628,7 +1632,7 @@ func (l *localDriver) GetDriverInfo() *storageframework.DriverInfo {
func (l *localDriver) SkipUnsupportedTest(pattern storageframework.TestPattern) {
}
func (l *localDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (l *localDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
var err error
l.node, err = e2enode.GetRandomReadySchedulableNode(f.ClientSet)
framework.ExpectNoError(err)
@@ -1650,14 +1654,13 @@ func (l *localDriver) PrepareTest(f *framework.Framework) (*storageframework.Per
}
}
ginkgo.DeferCleanup(l.hostExec.Cleanup)
return &storageframework.PerTestConfig{
Driver: l,
Prefix: "local",
Framework: f,
ClientNodeSelection: e2epod.NodeSelection{Name: l.node.Name},
}, func() {
l.hostExec.Cleanup()
}
Driver: l,
Prefix: "local",
Framework: f,
ClientNodeSelection: e2epod.NodeSelection{Name: l.node.Name},
}
}
func (l *localDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {
@@ -1848,12 +1851,12 @@ func (a *azureFileDriver) GetDynamicProvisionStorageClass(config *storageframewo
return storageframework.GetStorageClass(provisioner, parameters, &immediateBinding, ns)
}
func (a *azureFileDriver) PrepareTest(f *framework.Framework) (*storageframework.PerTestConfig, func()) {
func (a *azureFileDriver) PrepareTest(f *framework.Framework) *storageframework.PerTestConfig {
return &storageframework.PerTestConfig{
Driver: a,
Prefix: "azure-file",
Framework: f,
}, func() {}
}
}
func (a *azureFileDriver) CreateVolume(config *storageframework.PerTestConfig, volType storageframework.TestVolType) storageframework.TestVolume {