From 4ed187eb3f9509e40d4206c8a20f6fdfc7dc80be Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 7 Aug 2019 20:23:39 +0530 Subject: [PATCH] Fix issues in E2E cleanup Signed-off-by: Madhu Rajanna --- e2e/cephfs.go | 28 +++++++++++++++++++++------- e2e/rbd.go | 28 +++++++++++++++++++++------- e2e/utils.go | 17 ++++++++--------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index ceb3a2b75..9cf788121 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -36,6 +36,25 @@ func deployCephfsPlugin() { framework.RunKubectlOrDie("apply", "-f", cephfsDirPath+cephfsNodePluginRBAC) } +func deleteCephfsPlugin() { + _, err := framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisioner) + if err != nil { + e2elog.Logf("failed to delete cephfs provisioner %v", err) + } + _, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisionerRBAC) + if err != nil { + e2elog.Logf("failed to delete cephfs provisioner rbac %v", err) + } + _, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePlugin) + if err != nil { + e2elog.Logf("failed to delete cephfs nodeplugin %v", err) + } + _, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePluginRBAC) + if err != nil { + e2elog.Logf("failed to delete cephfs nodeplugin rbac %v", err) + } +} + var _ = Describe("cephfs", func() { f := framework.NewDefaultFramework("cephfs") // deploy cephfs CSI @@ -48,13 +67,8 @@ var _ = Describe("cephfs", func() { }) AfterEach(func() { - cephfsFiles := getFilesinDirectory(cephfsDirPath) - for _, file := range cephfsFiles { - res, err := framework.RunKubectl("delete", "-f", cephfsDirPath+file.Name()) - if err != nil { - e2elog.Logf("failed to delete resource in %s with err %v", res, err) - } - } + deleteCephfsPlugin() + deleteConfiMap(cephfsDirPath) deleteResource(cephfsExamplePath + "secret.yaml") deleteResource(cephfsExamplePath + "storageclass.yaml") deleteFileSystem() diff --git a/e2e/rbd.go b/e2e/rbd.go index c769aaf11..375119e3d 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -38,6 +38,25 @@ func deployRBDPlugin() { framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdNodePluginRBAC) } +func deleteRBDPlugin() { + _, err := framework.RunKubectl("delete", "-f", rbdDirPath+rbdProvisioner) + if err != nil { + e2elog.Logf("failed to delete rbd provisioner %v", err) + } + _, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdProvisionerRBAC) + if err != nil { + e2elog.Logf("failed to delete provisioner rbac %v", err) + } + _, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdNodePlugin) + if err != nil { + e2elog.Logf("failed to delete nodeplugin %v", err) + } + _, err = framework.RunKubectl("delete", "-f", rbdDirPath+rbdNodePluginRBAC) + if err != nil { + e2elog.Logf("failed to delete nodeplugin rbac %v", err) + } +} + var _ = Describe("RBD", func() { f := framework.NewDefaultFramework("rbd") // deploy RBD CSI @@ -52,13 +71,8 @@ var _ = Describe("RBD", func() { }) AfterEach(func() { - rbdFiles := getFilesinDirectory(rbdDirPath) - for _, file := range rbdFiles { - res, err := framework.RunKubectl("delete", "-f", rbdDirPath+file.Name()) - if err != nil { - e2elog.Logf("failed to delete resource in %s with err %v", res, err) - } - } + deleteRBDPlugin() + deleteConfiMap(rbdDirPath) deleteRBDPool() deleteResource(rbdExamplePath + "secret.yaml") deleteResource(rbdExamplePath + "storageclass.yaml") diff --git a/e2e/utils.go b/e2e/utils.go index 1bef73753..8bebb6a4f 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "os" "strings" "time" @@ -30,14 +29,6 @@ import ( testutils "k8s.io/kubernetes/test/utils" ) -func getFilesinDirectory(path string) []os.FileInfo { - files, err := ioutil.ReadDir(path) - if err != nil { - framework.ExpectNoError(err) - } - return files -} - var poll = 2 * time.Second type snapInfo struct { @@ -263,6 +254,14 @@ func createRBDSnapshotClass(f *framework.Framework) { Expect(err).Should(BeNil()) } +func deleteConfiMap(pluginPath string) { + path := pluginPath + configMap + _, err := framework.RunKubectl("delete", "-f", path) + if err != nil { + e2elog.Logf("failed to delete configmap %v", err) + } +} + func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Framework) { path := pluginPath + configMap cm := v1.ConfigMap{}