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 (
|
|
|
|
cephfsProvisioner = "csi-cephfsplugin-provisioner.yaml"
|
|
|
|
cephfsProvisionerRBAC = "csi-provisioner-rbac.yaml"
|
|
|
|
cephfsNodePlugin = "csi-cephfsplugin.yaml"
|
|
|
|
cephfsNodePluginRBAC = "csi-nodeplugin-rbac.yaml"
|
2019-06-10 08:00:40 +00:00
|
|
|
cephfsDeploymentName = "csi-cephfsplugin-provisioner"
|
|
|
|
cephfsDeamonSetName = "csi-cephfsplugin"
|
2019-07-25 06:49:44 +00:00
|
|
|
cephfsDirPath = "../deploy/cephfs/kubernetes"
|
2019-06-10 08:00:40 +00:00
|
|
|
cephfsExamplePath = "../examples/cephfs/"
|
2019-05-31 09:34:04 +00:00
|
|
|
)
|
|
|
|
|
2019-07-25 06:49:44 +00:00
|
|
|
func updateCephfsDirPath(c clientset.Interface) {
|
|
|
|
version := getKubeVersionToDeploy(c)
|
|
|
|
cephfsDirPath = fmt.Sprintf("%s/%s/", cephfsDirPath, version)
|
|
|
|
}
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
func deployCephfsPlugin() {
|
2019-12-11 08:48:36 +00:00
|
|
|
// delete objects deployed by rook
|
|
|
|
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", cephfsDirPath+cephfsProvisionerRBAC)
|
|
|
|
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", cephfsDirPath+cephfsNodePluginRBAC)
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy provisioner
|
2019-05-31 09:34:04 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisioner)
|
2019-12-11 08:48:36 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisionerRBAC)
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy nodeplugin
|
2019-05-31 09:34:04 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePlugin)
|
2019-12-11 08:48:36 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePluginRBAC)
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 14:53:39 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
var _ = Describe("cephfs", func() {
|
|
|
|
f := framework.NewDefaultFramework("cephfs")
|
2019-12-18 08:41:20 +00:00
|
|
|
var c clientset.Interface
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy cephfs CSI
|
2019-05-31 09:34:04 +00:00
|
|
|
BeforeEach(func() {
|
2019-12-18 08:41:20 +00:00
|
|
|
c = f.ClientSet
|
2019-07-25 06:49:44 +00:00
|
|
|
updateCephfsDirPath(f.ClientSet)
|
|
|
|
createConfigMap(cephfsDirPath, f.ClientSet, f)
|
2019-05-31 09:34:04 +00:00
|
|
|
deployCephfsPlugin()
|
|
|
|
createCephfsSecret(f.ClientSet, f)
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
2019-12-18 08:41:20 +00:00
|
|
|
if CurrentGinkgoTestDescription().Failed {
|
|
|
|
// log provisoner
|
|
|
|
logsCSIPods("app=csi-cephfsplugin-provisioner", c)
|
|
|
|
// log node plugin
|
|
|
|
logsCSIPods("app=csi-cephfsplugin", c)
|
|
|
|
}
|
2019-08-07 14:53:39 +00:00
|
|
|
deleteCephfsPlugin()
|
2019-12-04 01:35:02 +00:00
|
|
|
deleteConfigMap(cephfsDirPath)
|
2019-06-14 09:26:17 +00:00
|
|
|
deleteResource(cephfsExamplePath + "secret.yaml")
|
|
|
|
deleteResource(cephfsExamplePath + "storageclass.yaml")
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Context("Test cephfs CSI", func() {
|
|
|
|
It("Test cephfs CSI", func() {
|
2019-06-18 07:07:11 +00:00
|
|
|
pvcPath := cephfsExamplePath + "pvc.yaml"
|
|
|
|
appPath := cephfsExamplePath + "pod.yaml"
|
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 {
|
2020-01-16 09:26:51 +00:00
|
|
|
err = waitForStatefulSetReplicasReady(cephfsDeploymentName, namespace, f.ClientSet, 1*time.Second, timeout)
|
2019-07-25 06:49:44 +00:00
|
|
|
} else {
|
|
|
|
err = waitForDeploymentComplete(cephfsDeploymentName, 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(cephfsDeamonSetName, namespace, f.ClientSet, deployTimeout)
|
2019-05-31 09:34:04 +00:00
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:40:48 +00:00
|
|
|
By("create a storage class with pool and a PVC then Bind it to an app", func() {
|
|
|
|
createCephfsStorageClass(f.ClientSet, f, true)
|
|
|
|
validatePVCAndAppBinding(pvcPath, appPath, f)
|
|
|
|
deleteResource(cephfsExamplePath + "storageclass.yaml")
|
|
|
|
})
|
|
|
|
|
|
|
|
createCephfsStorageClass(f.ClientSet, f, false)
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
By("create and delete a PVC", func() {
|
|
|
|
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-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())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// TODO add cephfs backend validation
|
|
|
|
|
|
|
|
// 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())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
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-11-25 11:09:24 +00:00
|
|
|
By("Resize PVC and check application directory size", func() {
|
|
|
|
v, err := f.ClientSet.Discovery().ServerVersion()
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to get server version with error %v", err)
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize 0.3.0 is only supported from v1.15+
|
|
|
|
if v.Major > "1" || (v.Major == "1" && v.Minor >= "15") {
|
|
|
|
err := resizePVCAndValidateSize(pvcPath, appPath, f)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to resize PVC %v", err)
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2019-07-03 10:02:36 +00:00
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
2019-06-14 09:26:17 +00:00
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|