mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
Add E2E for cephfs resize functionality
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
daad8070ac
commit
ac09c5553c
@ -157,6 +157,23 @@ var _ = Describe("cephfs", func() {
|
||||
Fail(err.Error())
|
||||
}
|
||||
})
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
110
e2e/utils.go
110
e2e/utils.go
@ -18,6 +18,7 @@ import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
scv1 "k8s.io/api/storage/v1"
|
||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
@ -797,8 +798,8 @@ func checkDataPersist(pvcPath, appPath string, f *framework.Framework) error {
|
||||
if pvc == nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pvc.Namespace = f.UniqueName
|
||||
e2elog.Logf("The PVC template %+v", pvc)
|
||||
|
||||
app, err := loadApp(appPath)
|
||||
if err != nil {
|
||||
@ -839,3 +840,110 @@ func checkDataPersist(pvcPath, appPath string, f *framework.Framework) error {
|
||||
err = deletePVCAndApp("", f, pvc, app)
|
||||
return err
|
||||
}
|
||||
|
||||
func expandPVCSize(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, size string, t int) error {
|
||||
pvcName := pvc.Name
|
||||
updatedPVC := pvc.DeepCopy()
|
||||
var err error
|
||||
|
||||
updatedPVC, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(pvcName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error fetching pvc %q with %v", pvcName, err)
|
||||
}
|
||||
timeout := time.Duration(t) * time.Minute
|
||||
|
||||
updatedPVC.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(size)
|
||||
_, err = c.CoreV1().PersistentVolumeClaims(updatedPVC.Namespace).Update(updatedPVC)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
start := time.Now()
|
||||
e2elog.Logf("Waiting up to %v to be in Resized state", pvc)
|
||||
return wait.PollImmediate(poll, timeout, func() (bool, error) {
|
||||
e2elog.Logf("waiting for PVC %s (%d seconds elapsed)", updatedPVC.Name, int(time.Since(start).Seconds()))
|
||||
updatedPVC, err = c.CoreV1().PersistentVolumeClaims(updatedPVC.Namespace).Get(pvcName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
e2elog.Logf("Error getting pvc in namespace: '%s': %v", updatedPVC.Namespace, err)
|
||||
if testutils.IsRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
pvcConditions := updatedPVC.Status.Conditions
|
||||
if len(pvcConditions) > 0 {
|
||||
if pvcConditions[0].Type == v1.PersistentVolumeClaimResizing {
|
||||
return true, nil
|
||||
}
|
||||
e2elog.Logf("pvc state %v", pvcConditions[0].Type)
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
}
|
||||
|
||||
func resizePVCAndValidateSize(pvcPath, appPath string, f *framework.Framework) error {
|
||||
pvc, err := loadPVC(pvcPath)
|
||||
if pvc == nil {
|
||||
return err
|
||||
}
|
||||
pvc.Namespace = f.UniqueName
|
||||
|
||||
resizePvc, err := loadPVC(pvcPath)
|
||||
if resizePvc == nil {
|
||||
return err
|
||||
}
|
||||
resizePvc.Namespace = f.UniqueName
|
||||
|
||||
app, err := loadApp(appPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
app.Labels = map[string]string{"app": "resize-pvc"}
|
||||
app.Namespace = f.UniqueName
|
||||
|
||||
err = createPVCAndApp("", f, pvc, app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opt := metav1.ListOptions{
|
||||
LabelSelector: "app=resize-pvc",
|
||||
}
|
||||
|
||||
err = checkDirSize(app, f, &opt, "5.0G", deployTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// resize PVC
|
||||
err = expandPVCSize(f.ClientSet, resizePvc, "10Gi", deployTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// wait for application pod to come up after resize
|
||||
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = checkDirSize(app, f, &opt, "10G", deployTimeout)
|
||||
return err
|
||||
}
|
||||
|
||||
func checkDirSize(app *v1.Pod, f *framework.Framework, opt *metav1.ListOptions, size string, t int) error {
|
||||
dirPath := app.Spec.Containers[0].VolumeMounts[0].MountPath
|
||||
timeout := time.Duration(t) * time.Minute
|
||||
start := time.Now()
|
||||
|
||||
return wait.PollImmediate(poll, timeout, func() (bool, error) {
|
||||
e2elog.Logf("checking directory size %s (%d seconds elapsed)", dirPath, int(time.Since(start).Seconds()))
|
||||
output, stdErr := execCommandInPod(f, fmt.Sprintf("df -h|grep %s |awk '{print $2}'", dirPath), app.Namespace, opt)
|
||||
|
||||
if stdErr != "" {
|
||||
e2elog.Logf("failed to execute command in app pod %v", stdErr)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if !strings.Contains(output, size) {
|
||||
e2elog.Logf("expected directory size %s found %s information", size, output)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user