2020-07-25 16:39:50 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-30 13:27:33 +00:00
|
|
|
"fmt"
|
2020-07-25 16:39:50 +00:00
|
|
|
"os"
|
2020-09-30 13:27:33 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2020-07-25 16:39:50 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo" // nolint
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
clientset "k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("CephFS Upgrade Testing", func() {
|
|
|
|
f := framework.NewDefaultFramework("upgrade-test-cephfs")
|
|
|
|
var (
|
2020-09-30 13:27:33 +00:00
|
|
|
c clientset.Interface
|
|
|
|
pvc *v1.PersistentVolumeClaim
|
|
|
|
pvcClone *v1.PersistentVolumeClaim
|
|
|
|
app *v1.Pod
|
|
|
|
appClone *v1.Pod
|
2020-07-25 16:39:50 +00:00
|
|
|
// cwd stores the initial working directory.
|
|
|
|
cwd string
|
2020-09-03 09:34:29 +00:00
|
|
|
err error
|
2020-09-30 13:27:33 +00:00
|
|
|
// checkSum stores the md5sum of a file to verify uniqueness.
|
|
|
|
checkSum string
|
|
|
|
// newCheckSum stores the md5sum of a file in the cloned pvc.
|
|
|
|
newCheckSum string
|
|
|
|
)
|
|
|
|
const (
|
|
|
|
pvcSize = "2Gi"
|
|
|
|
appKey = "app"
|
|
|
|
appLabel = "cephfs-upgrade-testing"
|
2020-07-25 16:39:50 +00:00
|
|
|
)
|
2021-09-20 10:16:55 +00:00
|
|
|
// deploy cephFS CSI
|
2020-07-25 16:39:50 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
if !upgradeTesting || !testCephFS {
|
|
|
|
Skip("Skipping CephFS Upgrade Test")
|
|
|
|
}
|
|
|
|
c = f.ClientSet
|
|
|
|
if cephCSINamespace != defaultNs {
|
2020-09-03 09:34:29 +00:00
|
|
|
err = createNamespace(c, cephCSINamespace)
|
2020-07-25 16:39:50 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create namespace: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetch current working directory to switch back
|
|
|
|
// when we are done upgrading.
|
|
|
|
cwd, err = os.Getwd()
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to getwd: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
err = upgradeAndDeployCSI(upgradeVersion, "cephfs")
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to upgrade csi: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = createConfigMap(cephFSDirPath, f.ClientSet, f)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-02-22 11:13:40 +00:00
|
|
|
var key string
|
|
|
|
// create cephFS provisioner secret
|
|
|
|
key, err = createCephUser(f, keyringCephFSProvisionerUsername, cephFSProvisionerCaps())
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create user %s: %v", keyringCephFSProvisionerUsername, err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-02-22 11:13:40 +00:00
|
|
|
err = createCephfsSecret(f, cephFSProvisionerSecretName, keyringCephFSProvisionerUsername, key)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create provisioner secret: %v", err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
// create cephFS plugin secret
|
|
|
|
key, err = createCephUser(f, keyringCephFSNodePluginUsername, cephFSNodePluginCaps())
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create user %s: %v", keyringCephFSNodePluginUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
err = createCephfsSecret(f, cephFSNodePluginSecretName, keyringCephFSNodePluginUsername, key)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create node secret: %v", err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 13:27:33 +00:00
|
|
|
err = createCephFSSnapshotClass(f)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create snapshotclass: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
2020-09-21 14:56:15 +00:00
|
|
|
err = createCephfsStorageClass(f.ClientSet, f, true, nil)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create storageclass: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
AfterEach(func() {
|
|
|
|
if !testCephFS || !upgradeTesting {
|
|
|
|
Skip("Skipping CephFS Upgrade Test")
|
|
|
|
}
|
|
|
|
if CurrentGinkgoTestDescription().Failed {
|
|
|
|
// log pods created by helm chart
|
|
|
|
logsCSIPods("app=ceph-csi-cephfs", c)
|
|
|
|
// log provisoner
|
|
|
|
logsCSIPods("app=csi-cephfsplugin-provisioner", c)
|
|
|
|
// log node plugin
|
|
|
|
logsCSIPods("app=csi-cephfsplugin", c)
|
2020-12-03 11:00:22 +00:00
|
|
|
|
|
|
|
// log all details from the namespace where Ceph-CSI is deployed
|
|
|
|
framework.DumpAllNamespaceInfo(c, cephCSINamespace)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteConfigMap(cephFSDirPath)
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete configmap: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-06-25 13:07:12 +00:00
|
|
|
err = c.CoreV1().
|
|
|
|
Secrets(cephCSINamespace).
|
|
|
|
Delete(context.TODO(), cephFSProvisionerSecretName, metav1.DeleteOptions{})
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete provisioner secret: %v", err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
2021-06-25 13:07:12 +00:00
|
|
|
err = c.CoreV1().
|
|
|
|
Secrets(cephCSINamespace).
|
|
|
|
Delete(context.TODO(), cephFSNodePluginSecretName, metav1.DeleteOptions{})
|
2021-02-22 11:13:40 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete node secret: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete storageclass: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2021-09-20 10:16:55 +00:00
|
|
|
err = deleteResource(cephFSExamplePath + "snapshotclass.yaml")
|
2020-09-30 13:27:33 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete storageclass: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
2020-07-25 16:39:50 +00:00
|
|
|
if deployCephFS {
|
|
|
|
deleteCephfsPlugin()
|
|
|
|
if cephCSINamespace != defaultNs {
|
2020-09-30 13:27:33 +00:00
|
|
|
err = deleteNamespace(c, cephCSINamespace)
|
2020-07-25 16:39:50 +00:00
|
|
|
if err != nil {
|
2020-09-03 09:34:29 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete namespace: %v", err)
|
2020-09-03 09:34:29 +00:00
|
|
|
}
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("Cephfs Upgrade Test", func() {
|
|
|
|
It("Cephfs Upgrade Test", func() {
|
2020-09-30 13:27:33 +00:00
|
|
|
By("checking provisioner deployment is running", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
err = waitForDeploymentComplete(cephFSDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout)
|
2020-09-30 13:27:33 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
By("checking nodeplugin deamonset pods are running", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
err = waitForDaemonSets(cephFSDeamonSetName, cephCSINamespace, f.ClientSet, deployTimeout)
|
2020-09-30 13:27:33 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("timeout waiting for daemonset %s: %v", cephFSDeamonSetName, err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
})
|
2020-07-25 16:39:50 +00:00
|
|
|
|
|
|
|
By("upgrade to latest changes and verify app re-mount", func() {
|
|
|
|
// TODO: fetch pvc size from spec.
|
2021-09-20 10:16:55 +00:00
|
|
|
pvcPath := cephFSExamplePath + "pvc.yaml"
|
|
|
|
appPath := cephFSExamplePath + "pod.yaml"
|
2020-09-30 13:27:33 +00:00
|
|
|
data := "check data persists"
|
|
|
|
label := make(map[string]string)
|
2020-10-14 09:25:49 +00:00
|
|
|
|
2020-07-25 16:39:50 +00:00
|
|
|
pvc, err = loadPVC(pvcPath)
|
2020-10-20 09:55:09 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to load pvc: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
pvc.Namespace = f.UniqueName
|
|
|
|
|
|
|
|
app, err = loadApp(appPath)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to load application: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
2020-09-30 13:27:33 +00:00
|
|
|
label[appKey] = appLabel
|
2020-07-25 16:39:50 +00:00
|
|
|
app.Namespace = f.UniqueName
|
2020-09-30 13:27:33 +00:00
|
|
|
app.Labels = label
|
|
|
|
pvc.Namespace = f.UniqueName
|
2020-07-25 16:39:50 +00:00
|
|
|
pvc.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(pvcSize)
|
|
|
|
err = createPVCAndApp("", f, pvc, app, deployTimeout)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create pvc and application: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
2020-09-30 13:27:33 +00:00
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
// fetch the path where volume is mounted.
|
|
|
|
mountPath := app.Spec.Containers[0].VolumeMounts[0].MountPath
|
|
|
|
filePath := filepath.Join(mountPath, "testClone")
|
|
|
|
|
|
|
|
// create a test file at the mountPath.
|
2021-06-25 13:07:12 +00:00
|
|
|
_, stdErr := execCommandInPodAndAllowFail(
|
|
|
|
f,
|
|
|
|
fmt.Sprintf("echo %s > %s", data, filePath),
|
|
|
|
app.Namespace,
|
|
|
|
&opt)
|
2020-09-30 13:27:33 +00:00
|
|
|
if stdErr != "" {
|
|
|
|
e2elog.Failf("failed to write data to a file %s", stdErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// force an immediate write of all cached data to disk.
|
|
|
|
_, stdErr = execCommandInPodAndAllowFail(f, fmt.Sprintf("sync %s", filePath), app.Namespace, &opt)
|
|
|
|
if stdErr != "" {
|
|
|
|
e2elog.Failf("failed to sync data to a disk %s", stdErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
e2elog.Logf("Calculating checksum of %s", filePath)
|
|
|
|
checkSum, err = calculateSHA512sum(f, app, filePath, &opt)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to calculate checksum: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pvc clone is only supported from v1.16+
|
2020-10-14 09:25:49 +00:00
|
|
|
if k8sVersionGreaterEquals(f.ClientSet, 1, 17) {
|
2020-09-30 13:27:33 +00:00
|
|
|
// Create snapshot of the pvc
|
2021-09-20 10:16:55 +00:00
|
|
|
snapshotPath := cephFSExamplePath + "snapshot.yaml"
|
2020-09-30 13:27:33 +00:00
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Name = "cephfs-pvc-snapshot"
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
err = createSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to create snapshot %v", err)
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 16:39:50 +00:00
|
|
|
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete application: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
deleteCephfsPlugin()
|
|
|
|
|
|
|
|
// switch back to current changes.
|
|
|
|
err = os.Chdir(cwd)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to d chdir: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
deployCephfsPlugin()
|
|
|
|
|
2021-09-20 10:16:55 +00:00
|
|
|
err = waitForDeploymentComplete(cephFSDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout)
|
2021-05-17 09:58:15 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("timeout waiting for upgraded deployment %s: %v", cephFSDeploymentName, err)
|
2021-05-17 09:58:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 10:16:55 +00:00
|
|
|
err = waitForDaemonSets(cephFSDeamonSetName, cephCSINamespace, f.ClientSet, deployTimeout)
|
2021-05-17 09:58:15 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("timeout waiting for upgraded daemonset %s: %v", cephFSDeamonSetName, err)
|
2021-05-17 09:58:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 13:27:33 +00:00
|
|
|
app.Labels = label
|
2020-07-25 16:39:50 +00:00
|
|
|
// validate if the app gets bound to a pvc created by
|
|
|
|
// an earlier release.
|
|
|
|
err = createApp(f.ClientSet, app, deployTimeout)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create application: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-30 13:27:33 +00:00
|
|
|
By("Create clone from a snapshot", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
pvcClonePath := cephFSExamplePath + "pvc-restore.yaml"
|
|
|
|
appClonePath := cephFSExamplePath + "pod-restore.yaml"
|
2020-09-30 13:27:33 +00:00
|
|
|
label := make(map[string]string)
|
2020-10-14 09:25:49 +00:00
|
|
|
|
2020-09-30 13:27:33 +00:00
|
|
|
// pvc clone is only supported from v1.16+
|
2020-10-14 09:25:49 +00:00
|
|
|
if k8sVersionGreaterEquals(f.ClientSet, 1, 17) {
|
2020-09-30 13:27:33 +00:00
|
|
|
pvcClone, err = loadPVC(pvcClonePath)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to load pvc: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(pvcSize)
|
|
|
|
appClone, err = loadApp(appClonePath)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to load application: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
label[appKey] = "validate-snap-cephfs"
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
appClone.Name = "snap-clone-cephfs"
|
|
|
|
appClone.Labels = label
|
|
|
|
err = createPVCAndApp("", f, pvcClone, appClone, deployTimeout)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create pvc and application: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
mountPath := appClone.Spec.Containers[0].VolumeMounts[0].MountPath
|
|
|
|
testFilePath := filepath.Join(mountPath, "testClone")
|
|
|
|
newCheckSum, err = calculateSHA512sum(f, appClone, testFilePath, &opt)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to calculate checksum: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Compare(newCheckSum, checkSum) != 0 {
|
2021-06-25 13:07:12 +00:00
|
|
|
e2elog.Failf(
|
|
|
|
"The checksum of files did not match, expected %s received %s ",
|
|
|
|
checkSum,
|
|
|
|
newCheckSum)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
e2elog.Logf("The checksum of files matched")
|
|
|
|
|
|
|
|
// delete cloned pvc and pod
|
|
|
|
err = deletePVCAndApp("", f, pvcClone, appClone)
|
|
|
|
if err != nil {
|
|
|
|
Fail(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the snapshot of the parent pvc.
|
2021-09-20 10:16:55 +00:00
|
|
|
snapshotPath := cephFSExamplePath + "snapshot.yaml"
|
2020-09-30 13:27:33 +00:00
|
|
|
snap := getSnapshot(snapshotPath)
|
|
|
|
snap.Name = "cephfs-pvc-snapshot"
|
|
|
|
snap.Namespace = f.UniqueName
|
|
|
|
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
|
|
|
|
err = deleteSnapshot(&snap, deployTimeout)
|
|
|
|
if err != nil {
|
|
|
|
e2elog.Failf("failed to delete snapshot %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("Create clone from existing PVC", func() {
|
2021-09-20 10:16:55 +00:00
|
|
|
pvcSmartClonePath := cephFSExamplePath + "pvc-clone.yaml"
|
|
|
|
appSmartClonePath := cephFSExamplePath + "pod-clone.yaml"
|
2020-09-30 13:27:33 +00:00
|
|
|
label := make(map[string]string)
|
2020-10-14 09:25:49 +00:00
|
|
|
|
2020-09-30 13:27:33 +00:00
|
|
|
// pvc clone is only supported from v1.16+
|
2020-10-14 09:25:49 +00:00
|
|
|
if k8sVersionGreaterEquals(f.ClientSet, 1, 16) {
|
2020-09-30 13:27:33 +00:00
|
|
|
pvcClone, err = loadPVC(pvcSmartClonePath)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to load pvc: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
pvcClone.Spec.DataSource.Name = pvc.Name
|
|
|
|
pvcClone.Namespace = f.UniqueName
|
|
|
|
pvcClone.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(pvcSize)
|
|
|
|
appClone, err = loadApp(appSmartClonePath)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to load application: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
label[appKey] = "validate-snap-cephfs"
|
|
|
|
appClone.Namespace = f.UniqueName
|
|
|
|
appClone.Name = "appclone"
|
|
|
|
appClone.Labels = label
|
|
|
|
err = createPVCAndApp("", f, pvcClone, appClone, deployTimeout)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to create pvc and application: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
|
|
|
}
|
|
|
|
mountPath := appClone.Spec.Containers[0].VolumeMounts[0].MountPath
|
|
|
|
testFilePath := filepath.Join(mountPath, "testClone")
|
|
|
|
newCheckSum, err = calculateSHA512sum(f, appClone, testFilePath, &opt)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to calculate checksum: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Compare(newCheckSum, checkSum) != 0 {
|
2021-06-25 13:07:12 +00:00
|
|
|
e2elog.Failf(
|
|
|
|
"The checksum of files did not match, expected %s received %s",
|
|
|
|
checkSum,
|
|
|
|
newCheckSum)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
e2elog.Logf("The checksum of files matched")
|
|
|
|
|
|
|
|
// delete cloned pvc and pod
|
|
|
|
err = deletePVCAndApp("", f, pvcClone, appClone)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete pvc and application: %v", err)
|
2020-09-30 13:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-07-25 16:39:50 +00:00
|
|
|
By("Resize pvc and verify expansion", func() {
|
|
|
|
pvcExpandSize := "5Gi"
|
2020-09-30 13:27:33 +00:00
|
|
|
label := make(map[string]string)
|
2020-10-14 09:25:49 +00:00
|
|
|
|
2020-07-25 16:39:50 +00:00
|
|
|
// Resize 0.3.0 is only supported from v1.15+
|
2020-10-14 09:25:49 +00:00
|
|
|
if k8sVersionGreaterEquals(f.ClientSet, 1, 15) {
|
2020-09-30 13:27:33 +00:00
|
|
|
label[appKey] = appLabel
|
2020-07-25 16:39:50 +00:00
|
|
|
opt := metav1.ListOptions{
|
2020-09-30 13:27:33 +00:00
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
2021-06-25 13:07:12 +00:00
|
|
|
pvc, err = f.ClientSet.CoreV1().
|
|
|
|
PersistentVolumeClaims(pvc.Namespace).
|
|
|
|
Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
2020-07-25 16:39:50 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to get pvc: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resize PVC
|
|
|
|
err = expandPVCSize(f.ClientSet, pvc, pvcExpandSize, deployTimeout)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to expand pvc: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
// wait for application pod to come up after resize
|
2021-06-15 10:08:51 +00:00
|
|
|
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout, noError)
|
2020-07-25 16:39:50 +00:00
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("timeout waiting for pod to be in running state: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
// validate if resize is successful.
|
|
|
|
err = checkDirSize(app, f, &opt, pvcExpandSize)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to check directory size: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
By("delete pvc and app")
|
|
|
|
err = deletePVCAndApp("", f, pvc, app)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete pvc and application: %v", err)
|
2020-07-25 16:39:50 +00:00
|
|
|
}
|
2021-02-22 11:13:40 +00:00
|
|
|
// delete cephFS provisioner secret
|
|
|
|
err = deleteCephUser(f, keyringCephFSProvisionerUsername)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete user %s: %v", keyringCephFSProvisionerUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
|
|
|
// delete cephFS plugin secret
|
|
|
|
err = deleteCephUser(f, keyringCephFSNodePluginUsername)
|
|
|
|
if err != nil {
|
2021-11-22 06:53:14 +00:00
|
|
|
e2elog.Failf("failed to delete user %s: %v", keyringCephFSNodePluginUsername, err)
|
2021-02-22 11:13:40 +00:00
|
|
|
}
|
2020-07-25 16:39:50 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|