From e591b33fde9a21e7deafd4d3560744ceb5d6cd60 Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Fri, 7 Jul 2023 00:03:22 -0700 Subject: [PATCH 1/7] reszie cloned pvc based on cmp between cloned vs size and source pvc size --- controllers/pvc.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/controllers/pvc.go b/controllers/pvc.go index 074672d..6f71b31 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -106,6 +106,19 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste return err } + // check the size of source pvc with that of the cloned volumesnapshot + // The cloned pvc provisioning will fail if the source pvc spec.resources.requests.sotrage value is less than the volumesnapshot.status.restorSize value + // In order to tackle this problem we compare both the values and use the one that is maximum so that provisioning of cloned pvc does not fail + // currently we are keeping this pvc resizing a default behavior but this can be put behind a datamover feature boolean flag + + clonedVSRestoreSize := vsClone.Status.RestoreSize.Size() + sourcePVCRequestSize := sourcePVC.Spec.Resources.Size() + + clonedPVCSize := sourcePVCRequestSize + if clonedVSRestoreSize > sourcePVCRequestSize { + clonedPVCSize = clonedVSRestoreSize + } + if pvcClone.CreationTimestamp.IsZero() { apiGroup := "snapshot.storage.k8s.io" pvcClone.Spec.DataSource = &corev1.TypedLocalObjectReference{ @@ -143,6 +156,11 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste } pvcClone.Spec.Resources = sourcePVC.Spec.Resources + + // use the clonedPVCSize that is computed earlier + if clonedPVCSize != sourcePVCRequestSize { + pvcClone.Spec.Resources.Requests.Storage().Set(int64(clonedPVCSize)) + } } return nil From 14c6b865f498ee3e8efc598d37cc31fb16399fed Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Fri, 7 Jul 2023 11:15:10 -0700 Subject: [PATCH 2/7] minor update --- controllers/pvc.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/controllers/pvc.go b/controllers/pvc.go index 6f71b31..7ced87e 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -158,9 +158,7 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste pvcClone.Spec.Resources = sourcePVC.Spec.Resources // use the clonedPVCSize that is computed earlier - if clonedPVCSize != sourcePVCRequestSize { - pvcClone.Spec.Resources.Requests.Storage().Set(int64(clonedPVCSize)) - } + pvcClone.Spec.Resources.Requests.Storage().Set(int64(clonedPVCSize)) } return nil From e6d01c533fadd83f3502f107984c0a6cb3daf02d Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Mon, 17 Jul 2023 10:57:22 -0700 Subject: [PATCH 3/7] harden the logic to resize --- controllers/pvc.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/controllers/pvc.go b/controllers/pvc.go index 7ced87e..36959d9 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -107,17 +107,23 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste } // check the size of source pvc with that of the cloned volumesnapshot - // The cloned pvc provisioning will fail if the source pvc spec.resources.requests.sotrage value is less than the volumesnapshot.status.restorSize value + // The cloned pvc provisioning will fail if the source pvc spec.resources.requests.storage value is less than the volumesnapshot.status.restorSize value // In order to tackle this problem we compare both the values and use the one that is maximum so that provisioning of cloned pvc does not fail // currently we are keeping this pvc resizing a default behavior but this can be put behind a datamover feature boolean flag - clonedVSRestoreSize := vsClone.Status.RestoreSize.Size() - sourcePVCRequestSize := sourcePVC.Spec.Resources.Size() + clonedVSRestoreSize := vsClone.Status.RestoreSize + r.Log.Info(fmt.Sprintf("buildPVCClone: clonedVSRestoreSize: %v", clonedVSRestoreSize)) + sourcePVCRequestSize := sourcePVC.Spec.Resources.Requests.Storage() + r.Log.Info(fmt.Sprintf("buildPVCClone: sourcePVCRequestSize: %v", sourcePVCRequestSize)) clonedPVCSize := sourcePVCRequestSize - if clonedVSRestoreSize > sourcePVCRequestSize { + + cmpResult := clonedVSRestoreSize.Cmp(*sourcePVCRequestSize) + if cmpResult == 1 || cmpResult == 0 { + r.Log.Info(fmt.Sprintf("buildPVCClone: updating clonedPVCSize because clonedVSRestoreSize is greater than or equal to sourcePVCRequestSize")) clonedPVCSize = clonedVSRestoreSize } + r.Log.Info(fmt.Sprintf("buildPVCClone: updated clonedPVCSize: %s", clonedPVCSize)) if pvcClone.CreationTimestamp.IsZero() { apiGroup := "snapshot.storage.k8s.io" @@ -154,11 +160,12 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste if pvcClone.Spec.StorageClassName == nil { pvcClone.Spec.StorageClassName = sourcePVC.Spec.StorageClassName } - pvcClone.Spec.Resources = sourcePVC.Spec.Resources // use the clonedPVCSize that is computed earlier - pvcClone.Spec.Resources.Requests.Storage().Set(int64(clonedPVCSize)) + r.Log.Info(fmt.Sprintf("buildPVCClone: use the clonedPVCSize that is computed earlier")) + pvcClone.Spec.Resources.Requests.Storage().Set(clonedPVCSize.Value()) + r.Log.Info(fmt.Sprintf("buildPVCClone: updated size for pvcClone: %v", pvcClone.Spec.Resources.Requests.Storage().Value())) } return nil From 60ee1673dfb4b51b2e5702433e8895d774ebe19c Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Mon, 31 Jul 2023 21:06:39 -0700 Subject: [PATCH 4/7] use VSC size instead of VS --- controllers/pvc.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/controllers/pvc.go b/controllers/pvc.go index 36959d9..1a2876f 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -4,9 +4,8 @@ import ( "context" "errors" "fmt" - "os" - k8serrors "k8s.io/apimachinery/pkg/api/errors" + "os" "github.com/go-logr/logr" volsnapmoverv1alpha1 "github.com/konveyor/volume-snapshot-mover/api/v1alpha1" @@ -71,7 +70,7 @@ func (r *VolumeSnapshotBackupReconciler) MirrorPVC(log logr.Logger) (bool, error op, err := controllerutil.CreateOrUpdate(r.Context, r.Client, pvcClone, func() error { - return r.buildPVCClone(pvcClone, &vsClone) + return r.buildPVCClone(pvcClone, &vsClone, &vscClone) }) if err != nil { r.Log.Info(fmt.Sprintf("err building pvc clone: %v", err)) @@ -89,7 +88,7 @@ func (r *VolumeSnapshotBackupReconciler) MirrorPVC(log logr.Logger) (bool, error return true, nil } -func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.PersistentVolumeClaim, vsClone *snapv1.VolumeSnapshot) error { +func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.PersistentVolumeClaim, vsClone *snapv1.VolumeSnapshot, vscClone *snapv1.VolumeSnapshotContent) error { sourcePVC, err := r.getSourcePVC() if err != nil { return err @@ -106,22 +105,20 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste return err } - // check the size of source pvc with that of the cloned volumesnapshot - // The cloned pvc provisioning will fail if the source pvc spec.resources.requests.storage value is less than the volumesnapshot.status.restorSize value + // check the size of source pvc with that of the cloned volumesnapshotcontent + // The cloned pvc provisioning will fail if the source pvc spec.resources.requests.storage value is less than the volumesnapshotcontent.status.restorSize value // In order to tackle this problem we compare both the values and use the one that is maximum so that provisioning of cloned pvc does not fail // currently we are keeping this pvc resizing a default behavior but this can be put behind a datamover feature boolean flag - clonedVSRestoreSize := vsClone.Status.RestoreSize - r.Log.Info(fmt.Sprintf("buildPVCClone: clonedVSRestoreSize: %v", clonedVSRestoreSize)) + clonedVSCRestoreSize := vscClone.Status.RestoreSize + r.Log.Info(fmt.Sprintf("buildPVCClone: clonedVSRestoreSize: %v", clonedVSCRestoreSize)) sourcePVCRequestSize := sourcePVC.Spec.Resources.Requests.Storage() r.Log.Info(fmt.Sprintf("buildPVCClone: sourcePVCRequestSize: %v", sourcePVCRequestSize)) - clonedPVCSize := sourcePVCRequestSize - - cmpResult := clonedVSRestoreSize.Cmp(*sourcePVCRequestSize) - if cmpResult == 1 || cmpResult == 0 { - r.Log.Info(fmt.Sprintf("buildPVCClone: updating clonedPVCSize because clonedVSRestoreSize is greater than or equal to sourcePVCRequestSize")) - clonedPVCSize = clonedVSRestoreSize + clonedPVCSize, _ := sourcePVCRequestSize.AsInt64() + sourcePVCRequestSizeInt, _ := sourcePVCRequestSize.AsInt64() + if *clonedVSCRestoreSize > sourcePVCRequestSizeInt { + clonedPVCSize = *clonedVSCRestoreSize } r.Log.Info(fmt.Sprintf("buildPVCClone: updated clonedPVCSize: %s", clonedPVCSize)) @@ -164,7 +161,7 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste // use the clonedPVCSize that is computed earlier r.Log.Info(fmt.Sprintf("buildPVCClone: use the clonedPVCSize that is computed earlier")) - pvcClone.Spec.Resources.Requests.Storage().Set(clonedPVCSize.Value()) + pvcClone.Spec.Resources.Requests.Storage().Set(clonedPVCSize) r.Log.Info(fmt.Sprintf("buildPVCClone: updated size for pvcClone: %v", pvcClone.Spec.Resources.Requests.Storage().Value())) } From 0c270939a24e070a3a200de2d63d397dc048f4cd Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Mon, 31 Jul 2023 21:15:37 -0700 Subject: [PATCH 5/7] minor fix --- controllers/pvc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/pvc.go b/controllers/pvc.go index 1a2876f..bfdc2d5 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -120,7 +120,7 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste if *clonedVSCRestoreSize > sourcePVCRequestSizeInt { clonedPVCSize = *clonedVSCRestoreSize } - r.Log.Info(fmt.Sprintf("buildPVCClone: updated clonedPVCSize: %s", clonedPVCSize)) + r.Log.Info(fmt.Sprintf("buildPVCClone: updated clonedPVCSize: %v", clonedPVCSize)) if pvcClone.CreationTimestamp.IsZero() { apiGroup := "snapshot.storage.k8s.io" From edc96c10d313e7902ef64e44f26d7f9f8eac639d Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Thu, 3 Aug 2023 14:31:07 -0700 Subject: [PATCH 6/7] set cloned PVC storage request from clone VSC restoreSize --- controllers/pvc.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/controllers/pvc.go b/controllers/pvc.go index bfdc2d5..8b26713 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" k8serrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/api/resource" "os" "github.com/go-logr/logr" @@ -111,7 +112,7 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste // currently we are keeping this pvc resizing a default behavior but this can be put behind a datamover feature boolean flag clonedVSCRestoreSize := vscClone.Status.RestoreSize - r.Log.Info(fmt.Sprintf("buildPVCClone: clonedVSRestoreSize: %v", clonedVSCRestoreSize)) + r.Log.Info(fmt.Sprintf("buildPVCClone: clonedVSRestoreSize: %d", *clonedVSCRestoreSize)) sourcePVCRequestSize := sourcePVC.Spec.Resources.Requests.Storage() r.Log.Info(fmt.Sprintf("buildPVCClone: sourcePVCRequestSize: %v", sourcePVCRequestSize)) @@ -157,11 +158,17 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste if pvcClone.Spec.StorageClassName == nil { pvcClone.Spec.StorageClassName = sourcePVC.Spec.StorageClassName } - pvcClone.Spec.Resources = sourcePVC.Spec.Resources + //pvcClone.Spec.Resources = sourcePVC.Spec.Resources // use the clonedPVCSize that is computed earlier r.Log.Info(fmt.Sprintf("buildPVCClone: use the clonedPVCSize that is computed earlier")) - pvcClone.Spec.Resources.Requests.Storage().Set(clonedPVCSize) + //pvcClone.Spec.Resources.Requests.Storage().Set(clonedPVCSize) + storageRequestValue := resource.NewQuantity(clonedPVCSize, resource.BinarySI) + pvcClone.Spec.Resources = corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: *storageRequestValue, + }, + } r.Log.Info(fmt.Sprintf("buildPVCClone: updated size for pvcClone: %v", pvcClone.Spec.Resources.Requests.Storage().Value())) } @@ -195,6 +202,8 @@ func (r *VolumeSnapshotBackupReconciler) BindPVCToDummyPod(log logr.Logger) (boo return false, err } + r.Log.Info(fmt.Sprintf("BindPVCToDummyPod: cloned PVC after building storage value:%v ", clonedPVC.Spec.Resources.Requests.Storage().Value())) + // Bind the above cloned PVC to a dummy pod dp := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ From 19e0982f5ebfc92e6009494c89a48a2413a049a9 Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Thu, 24 Aug 2023 15:21:03 -0700 Subject: [PATCH 7/7] remove cu patch log statements --- controllers/pvc.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/controllers/pvc.go b/controllers/pvc.go index 8b26713..e6f2c25 100644 --- a/controllers/pvc.go +++ b/controllers/pvc.go @@ -112,16 +112,13 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste // currently we are keeping this pvc resizing a default behavior but this can be put behind a datamover feature boolean flag clonedVSCRestoreSize := vscClone.Status.RestoreSize - r.Log.Info(fmt.Sprintf("buildPVCClone: clonedVSRestoreSize: %d", *clonedVSCRestoreSize)) sourcePVCRequestSize := sourcePVC.Spec.Resources.Requests.Storage() - r.Log.Info(fmt.Sprintf("buildPVCClone: sourcePVCRequestSize: %v", sourcePVCRequestSize)) clonedPVCSize, _ := sourcePVCRequestSize.AsInt64() sourcePVCRequestSizeInt, _ := sourcePVCRequestSize.AsInt64() if *clonedVSCRestoreSize > sourcePVCRequestSizeInt { clonedPVCSize = *clonedVSCRestoreSize } - r.Log.Info(fmt.Sprintf("buildPVCClone: updated clonedPVCSize: %v", clonedPVCSize)) if pvcClone.CreationTimestamp.IsZero() { apiGroup := "snapshot.storage.k8s.io" @@ -158,11 +155,8 @@ func (r *VolumeSnapshotBackupReconciler) buildPVCClone(pvcClone *corev1.Persiste if pvcClone.Spec.StorageClassName == nil { pvcClone.Spec.StorageClassName = sourcePVC.Spec.StorageClassName } - //pvcClone.Spec.Resources = sourcePVC.Spec.Resources // use the clonedPVCSize that is computed earlier - r.Log.Info(fmt.Sprintf("buildPVCClone: use the clonedPVCSize that is computed earlier")) - //pvcClone.Spec.Resources.Requests.Storage().Set(clonedPVCSize) storageRequestValue := resource.NewQuantity(clonedPVCSize, resource.BinarySI) pvcClone.Spec.Resources = corev1.ResourceRequirements{ Requests: corev1.ResourceList{