2019-05-31 09:34:04 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2019-06-18 07:07:11 +00:00
|
|
|
"fmt"
|
2019-06-14 09:42:48 +00:00
|
|
|
"time"
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
. "github.com/onsi/ginkgo" // nolint
|
|
|
|
|
2019-07-25 06:49:44 +00:00
|
|
|
clientset "k8s.io/client-go/kubernetes"
|
2019-05-31 09:34:04 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2019-06-24 07:58:39 +00:00
|
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
2019-05-31 09:34:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
rbdProvisioner = "csi-rbdplugin-provisioner.yaml"
|
|
|
|
rbdProvisionerRBAC = "csi-provisioner-rbac.yaml"
|
|
|
|
rbdNodePlugin = "csi-rbdplugin.yaml"
|
|
|
|
rbdNodePluginRBAC = "csi-nodeplugin-rbac.yaml"
|
2019-07-25 06:49:44 +00:00
|
|
|
configMap = "csi-config-map.yaml"
|
|
|
|
rbdDirPath = "../deploy/rbd/kubernetes"
|
2019-06-10 08:00:40 +00:00
|
|
|
rbdExamplePath = "../examples/rbd/"
|
|
|
|
rbdDeploymentName = "csi-rbdplugin-provisioner"
|
|
|
|
rbdDaemonsetName = "csi-rbdplugin"
|
|
|
|
namespace = "default"
|
2019-05-31 09:34:04 +00:00
|
|
|
)
|
|
|
|
|
2019-07-25 06:49:44 +00:00
|
|
|
func updaterbdDirPath(c clientset.Interface) {
|
|
|
|
version := getKubeVersionToDeploy(c)
|
|
|
|
rbdDirPath = fmt.Sprintf("%s/%s/", rbdDirPath, version)
|
|
|
|
}
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
func deployRBDPlugin() {
|
|
|
|
// deploy provisioner
|
|
|
|
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdProvisioner)
|
|
|
|
framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdProvisionerRBAC)
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy nodeplugin
|
2019-05-31 09:34:04 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", rbdDirPath+rbdNodePlugin)
|
|
|
|
framework.RunKubectlOrDie("apply", "-f", rbdDirPath+rbdNodePluginRBAC)
|
|
|
|
}
|
|
|
|
|
2019-08-07 14:53:39 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
var _ = Describe("RBD", func() {
|
|
|
|
f := framework.NewDefaultFramework("rbd")
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy RBD CSI
|
2019-05-31 09:34:04 +00:00
|
|
|
BeforeEach(func() {
|
2019-07-25 06:49:44 +00:00
|
|
|
updaterbdDirPath(f.ClientSet)
|
2019-05-31 09:34:04 +00:00
|
|
|
createRBDPool()
|
2019-07-25 06:49:44 +00:00
|
|
|
createConfigMap(rbdDirPath, f.ClientSet, f)
|
2019-05-31 09:34:04 +00:00
|
|
|
deployRBDPlugin()
|
2019-09-19 17:11:32 +00:00
|
|
|
createRBDStorageClass(f.ClientSet, f, make(map[string]string))
|
2019-05-31 09:34:04 +00:00
|
|
|
createRBDSecret(f.ClientSet, f)
|
2019-06-14 09:26:17 +00:00
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
2019-08-07 14:53:39 +00:00
|
|
|
deleteRBDPlugin()
|
|
|
|
deleteConfiMap(rbdDirPath)
|
2019-05-31 09:34:04 +00:00
|
|
|
deleteRBDPool()
|
2019-06-14 09:26:17 +00:00
|
|
|
deleteResource(rbdExamplePath + "secret.yaml")
|
|
|
|
deleteResource(rbdExamplePath + "storageclass.yaml")
|
2019-08-13 09:40:08 +00:00
|
|
|
// deleteResource(rbdExamplePath + "snapshotclass.yaml")
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Context("Test RBD CSI", func() {
|
|
|
|
It("Test RBD CSI", func() {
|
2019-06-18 09:18:28 +00:00
|
|
|
pvcPath := rbdExamplePath + "pvc.yaml"
|
|
|
|
appPath := rbdExamplePath + "pod.yaml"
|
2019-12-18 08:36:47 +00:00
|
|
|
rawPvcPath := rbdExamplePath + "raw-block-pvc.yaml"
|
|
|
|
rawAppPath := rbdExamplePath + "raw-block-pod.yaml"
|
2019-08-13 09:40:08 +00:00
|
|
|
// pvcClonePath := rbdExamplePath + "pvc-restore.yaml"
|
|
|
|
// appClonePath := rbdExamplePath + "pod-restore.yaml"
|
|
|
|
// snapshotPath := rbdExamplePath + "snapshot.yaml"
|
2019-06-18 07:07:11 +00:00
|
|
|
|
2019-07-25 06:49:44 +00:00
|
|
|
By("checking provisioner statefulset/deployment is running")
|
2019-06-14 09:42:48 +00:00
|
|
|
timeout := time.Duration(deployTimeout) * time.Minute
|
2019-07-25 06:49:44 +00:00
|
|
|
var err error
|
|
|
|
sts := deployProvAsSTS(f.ClientSet)
|
|
|
|
if sts {
|
|
|
|
err = framework.WaitForStatefulSetReplicasReady(rbdDeploymentName, namespace, f.ClientSet, 1*time.Second, timeout)
|
|
|
|
} else {
|
|
|
|
err = waitForDeploymentComplete(rbdDeploymentName, namespace, f.ClientSet, deployTimeout)
|
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
By("checking nodeplugin deamonsets is running")
|
2019-06-10 08:00:40 +00:00
|
|
|
err = waitForDaemonSets(rbdDaemonsetName, namespace, f.ClientSet, deployTimeout)
|
2019-05-31 09:34:04 +00:00
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
By("create a PVC and Bind it to an app", func() {
|
|
|
|
validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
})
|
2019-06-11 12:40:31 +00:00
|
|
|
|
|
|
|
By("create a PVC and Bind it to an app with normal user", func() {
|
|
|
|
validateNormalUserPVCAccess(pvcPath, f)
|
|
|
|
})
|
2019-09-19 17:11:32 +00:00
|
|
|
// Skipping ext4 FS testing
|
|
|
|
|
|
|
|
By("create a PVC and Bind it to an app with ext4 as the FS ", func() {
|
|
|
|
deleteResource(rbdExamplePath + "storageclass.yaml")
|
|
|
|
createRBDStorageClass(f.ClientSet, f, map[string]string{"csi.storage.k8s.io/fstype": "ext4"})
|
|
|
|
validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
deleteResource(rbdExamplePath + "storageclass.yaml")
|
|
|
|
createRBDStorageClass(f.ClientSet, f, make(map[string]string))
|
|
|
|
})
|
|
|
|
|
2019-08-13 09:40:08 +00:00
|
|
|
// skipping snapshot testing
|
|
|
|
|
|
|
|
// By("create a PVC clone and Bind it to an app", func() {
|
|
|
|
// createRBDSnapshotClass(f)
|
|
|
|
// pvc, err := loadPVC(pvcPath)
|
|
|
|
// if err != nil {
|
|
|
|
// Fail(err.Error())
|
|
|
|
// }
|
|
|
|
|
|
|
|
// pvc.Namespace = f.UniqueName
|
|
|
|
// e2elog.Logf("The PVC template %+v", pvc)
|
|
|
|
// err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
// if err != nil {
|
|
|
|
// Fail(err.Error())
|
|
|
|
// }
|
|
|
|
// // validate created backend rbd images
|
|
|
|
// images := listRBDImages(f)
|
|
|
|
// if len(images) != 1 {
|
|
|
|
// e2elog.Logf("backend image count %d expected image count %d", len(images), 1)
|
|
|
|
// Fail("validate backend image failed")
|
|
|
|
// }
|
|
|
|
// snap := getSnapshot(snapshotPath)
|
|
|
|
// snap.Namespace = f.UniqueName
|
|
|
|
// snap.Spec.Source.Name = pvc.Name
|
|
|
|
// snap.Spec.Source.Kind = "PersistentVolumeClaim"
|
|
|
|
// err = createSnapshot(&snap, deployTimeout)
|
|
|
|
// if err != nil {
|
|
|
|
// Fail(err.Error())
|
|
|
|
// }
|
|
|
|
// pool := "replicapool"
|
|
|
|
// snapList, err := listSnapshots(f, pool, images[0])
|
|
|
|
// if err != nil {
|
|
|
|
// Fail(err.Error())
|
|
|
|
// }
|
|
|
|
// if len(snapList) != 1 {
|
|
|
|
// e2elog.Logf("backend snapshot not matching kube snap count,snap count = % kube snap count %d", len(snapList), 1)
|
|
|
|
// Fail("validate backend snapshot failed")
|
|
|
|
// }
|
|
|
|
|
|
|
|
// validatePVCAndAppBinding(pvcClonePath, appClonePath, f)
|
|
|
|
|
|
|
|
// err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
// if err != nil {
|
|
|
|
// Fail(err.Error())
|
|
|
|
// }
|
|
|
|
// err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
// if err != nil {
|
|
|
|
// Fail(err.Error())
|
|
|
|
// }
|
|
|
|
// })
|
2019-06-14 09:26:17 +00:00
|
|
|
|
2019-12-18 08:36:47 +00:00
|
|
|
By("create a block type PVC and Bind it to an app", func() {
|
|
|
|
validatePVCAndAppBinding(rawPvcPath, rawAppPath, f)
|
|
|
|
})
|
2019-06-18 07:07:11 +00:00
|
|
|
|
|
|
|
By("create/delete multiple PVCs and Apps", func() {
|
|
|
|
totalCount := 2
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
// create pvc and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, i)
|
|
|
|
err := createPVCAndApp(name, f, pvc, app)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// validate created backend rbd images
|
|
|
|
images := listRBDImages(f)
|
|
|
|
if len(images) != totalCount {
|
2019-06-24 07:58:39 +00:00
|
|
|
e2elog.Logf("backend image creation not matching pvc count, image count = % pvc count %d", len(images), totalCount)
|
2019-06-18 07:07:11 +00:00
|
|
|
Fail("validate multiple pvc failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete pvc and app
|
|
|
|
for i := 0; i < totalCount; i++ {
|
|
|
|
name := fmt.Sprintf("%s%d", f.UniqueName, i)
|
|
|
|
err := deletePVCAndApp(name, f, pvc, app)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate created backend rbd images
|
|
|
|
images = listRBDImages(f)
|
|
|
|
if len(images) > 0 {
|
2019-06-24 07:58:39 +00:00
|
|
|
e2elog.Logf("left out rbd backend images count %d", len(images))
|
2019-06-18 07:07:11 +00:00
|
|
|
Fail("validate multiple pvc failed")
|
|
|
|
}
|
2019-06-14 09:26:17 +00:00
|
|
|
})
|
2019-07-03 10:02:36 +00:00
|
|
|
|
|
|
|
By("check data persist after recreating pod with same pvc", func() {
|
|
|
|
err := checkDataPersist(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
})
|
2019-09-19 12:19:57 +00:00
|
|
|
|
|
|
|
By("Test unmount after nodeplugin restart", func() {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
app, err := loadApp(appPath)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
app.Namespace = f.UniqueName
|
|
|
|
err = createPVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete rbd nodeplugin pods
|
|
|
|
err = deletePodWithLabel("app=csi-rbdplugin")
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
// wait for nodeplugin pods to come up
|
|
|
|
err = waitForDaemonSets(rbdDaemonsetName, namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
})
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|