From 78e2e7a807636f0357d6bd90d10c2b7c0c724664 Mon Sep 17 00:00:00 2001 From: Shyamsundar Ranganathan Date: Thu, 20 Jul 2023 09:46:49 -0400 Subject: [PATCH] Add comment to function validateExistingPV[C] functions Attempting to improve code quality as changes are done around the code. In this case adding comments to related functions. Signed-off-by: Shyamsundar Ranganathan (cherry picked from commit ce7fe0367287a5dddefa2954fca2a84b1f3b17cd) --- controllers/vrg_volrep.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/controllers/vrg_volrep.go b/controllers/vrg_volrep.go index 469570fcd..bdc11dae5 100644 --- a/controllers/vrg_volrep.go +++ b/controllers/vrg_volrep.go @@ -1959,6 +1959,8 @@ func (v *VRGInstance) updateExistingPVForSync(pv *corev1.PersistentVolume) error return nil } +// validateExistingPV validates if an existing PV matches the passed in PV for certain fields. Returns error +// if a match fails or a match is not possible given the state of the existing PV func (v *VRGInstance) validateExistingPV(pv *corev1.PersistentVolume) error { log := v.log.WithValues("PV", pv.Name) @@ -2016,6 +2018,8 @@ func (v *VRGInstance) validateExistingPV(pv *corev1.PersistentVolume) error { return fmt.Errorf("found existing PV (%s) not restored by Ramen and not matching with backed up PV", existingPV.Name) } +// validateExistingPVC validates if an existing PVC matches the passed in PVC for certain fields. Returns error +// if a match fails or a match is not possible given the state of the existing PVC func (v *VRGInstance) validateExistingPVC(pvc *corev1.PersistentVolumeClaim) error { existingPVC := &corev1.PersistentVolumeClaim{} pvcNSName := types.NamespacedName{Name: pvc.Name, Namespace: pvc.Namespace} @@ -2025,24 +2029,19 @@ func (v *VRGInstance) validateExistingPVC(pvc *corev1.PersistentVolumeClaim) err return fmt.Errorf("failed to get existing PVC %s (%w)", pvcNSName.String(), err) } - // If PVC not "Bound" return error if existingPVC.Status.Phase != corev1.ClaimBound { return fmt.Errorf("PVC %s exists and is not bound (phase: %s)", pvcNSName.String(), existingPVC.Status.Phase) } - // If PVC is terminating return error if !existingPVC.DeletionTimestamp.IsZero() { return fmt.Errorf("existing bound PVC %s is being deleted", pvcNSName.String()) } - // Check match to the PV we expect PVC to be bound to if existingPVC.Spec.VolumeName != pvc.Spec.VolumeName { return fmt.Errorf("PVC %s exists and bound to a different PV %s than PV %s desired", pvcNSName.String(), existingPVC.Spec.VolumeName, pvc.Spec.VolumeName) } - // Should we check and see if PV in being deleted? Should we just treat it as exists - // and then we don't care if deletion takes place later, which is what we do now? v.log.Info(fmt.Sprintf("PVC %s exists and bound to desired PV %s", pvcNSName.String(), existingPVC.Spec.VolumeName)) return nil