2019-05-31 09:34:04 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2019-06-18 07:07:11 +00:00
|
|
|
"fmt"
|
2020-02-25 11:45:54 +00:00
|
|
|
"time"
|
2019-06-14 09:42:48 +00:00
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
. "github.com/onsi/ginkgo" // nolint
|
|
|
|
|
2020-02-25 11:45:54 +00:00
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
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"
|
2020-01-21 08:22:43 +00:00
|
|
|
cephfsProvisionerPSP = "csi-provisioner-psp.yaml"
|
2019-05-31 09:34:04 +00:00
|
|
|
cephfsNodePlugin = "csi-cephfsplugin.yaml"
|
|
|
|
cephfsNodePluginRBAC = "csi-nodeplugin-rbac.yaml"
|
2020-01-21 08:22:43 +00:00
|
|
|
cephfsNodePluginPSP = "csi-nodeplugin-psp.yaml"
|
2019-06-10 08:00:40 +00:00
|
|
|
cephfsDeploymentName = "csi-cephfsplugin-provisioner"
|
|
|
|
cephfsDeamonSetName = "csi-cephfsplugin"
|
2019-12-19 15:35:58 +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
|
|
|
)
|
|
|
|
|
|
|
|
func deployCephfsPlugin() {
|
2019-12-11 08:48:36 +00:00
|
|
|
// delete objects deployed by rook
|
2020-02-25 11:45:54 +00:00
|
|
|
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", cephfsDirPath+cephfsProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("delete", "--ignore-not-found=true", "-f", cephfsDirPath+cephfsNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy provisioner
|
2020-02-25 11:45:54 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisioner, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsProvisionerPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-06-10 06:48:41 +00:00
|
|
|
// deploy nodeplugin
|
2020-02-25 11:45:54 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePlugin, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", cephfsDirPath+cephfsNodePluginPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-05-31 09:34:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 14:53:39 +00:00
|
|
|
func deleteCephfsPlugin() {
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err := framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisioner, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-08-07 14:53:39 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete cephfs provisioner %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisionerRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-08-07 14:53:39 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete cephfs provisioner rbac %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsProvisionerPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-21 08:22:43 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete cephfs provisioner psp %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePlugin, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-08-07 14:53:39 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete cephfs nodeplugin %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePluginRBAC, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2019-08-07 14:53:39 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete cephfs nodeplugin rbac %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", cephfsDirPath+cephfsNodePluginPSP, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-21 08:22:43 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete cephfs nodeplugin psp %v", err)
|
|
|
|
}
|
2019-08-07 14:53:39 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
createConfigMap(cephfsDirPath, f.ClientSet, f)
|
2020-02-25 08:00:23 +00:00
|
|
|
if deployCephFS {
|
2020-02-25 11:45:54 +00:00
|
|
|
if cephCSINamespace != defaultNs {
|
|
|
|
// create namespace
|
|
|
|
ns := &v1.Namespace{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: cephCSINamespace,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err := c.CoreV1().Namespaces().Create(ns)
|
|
|
|
if err != nil && !apierrs.IsAlreadyExists(err) {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 08:00:23 +00:00
|
|
|
deployCephfsPlugin()
|
|
|
|
}
|
2019-05-31 09:34:04 +00:00
|
|
|
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-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")
|
2020-02-25 11:45:54 +00:00
|
|
|
if deployCephFS {
|
|
|
|
deleteCephfsPlugin()
|
|
|
|
if cephCSINamespace != defaultNs {
|
|
|
|
err := c.CoreV1().Namespaces().Delete(cephCSINamespace, nil)
|
|
|
|
if err != nil && !apierrs.IsNotFound(err) {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
err = framework.WaitForNamespacesDeleted(c, []string{cephCSINamespace}, time.Duration(deployTimeout)*time.Minute)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2019-12-19 15:35:58 +00:00
|
|
|
By("checking provisioner deployment is running")
|
2019-07-25 06:49:44 +00:00
|
|
|
var err error
|
2020-02-25 11:45:54 +00:00
|
|
|
err = waitForDeploymentComplete(cephfsDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout)
|
2019-05-31 09:34:04 +00:00
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
By("checking nodeplugin deamonsets is running")
|
2020-02-25 11:45:54 +00:00
|
|
|
err = waitForDaemonSets(cephfsDeamonSetName, cephCSINamespace, 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())
|
|
|
|
}
|
|
|
|
})
|
2020-01-23 01:47:02 +00:00
|
|
|
|
|
|
|
By("creating a PVC, deleting backing subvolume, and checking successful PV deletion", func() {
|
|
|
|
pvc, err := loadPVC(pvcPath)
|
|
|
|
if pvc == nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deleteBackingCephFSVolume(f, pvc)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
|
|
|
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
|
|
|
|
2020-01-31 08:49:11 +00:00
|
|
|
// Make sure this should be last testcase in this file, because
|
|
|
|
// it deletes pool
|
|
|
|
By("Create a PVC and Delete PVC when backend pool deleted", func() {
|
|
|
|
err := pvcDeleteWhenPoolNotFound(pvcPath, true, f)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
2019-06-14 09:26:17 +00:00
|
|
|
|
2019-05-31 09:34:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|