Skip to content

Commit 83274c8

Browse files
ShyamsundarRBenamarMk
authored andcommitted
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 <[email protected]> (cherry picked from commit cdc6052)
1 parent 907df82 commit 83274c8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

controllers/vrg_volrep.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,8 @@ func (v *VRGInstance) updateExistingPVForSync(pv *corev1.PersistentVolume) error
20152015
return nil
20162016
}
20172017

2018+
// validateExistingPV validates if an existing PV matches the passed in PV for certain fields. Returns error
2019+
// if a match fails or a match is not possible given the state of the existing PV
20182020
func (v *VRGInstance) validateExistingPV(pv *corev1.PersistentVolume) error {
20192021
log := v.log.WithValues("PV", pv.Name)
20202022

@@ -2072,6 +2074,8 @@ func (v *VRGInstance) validateExistingPV(pv *corev1.PersistentVolume) error {
20722074
return fmt.Errorf("found existing PV (%s) not restored by Ramen and not matching with backed up PV", existingPV.Name)
20732075
}
20742076

2077+
// validateExistingPVC validates if an existing PVC matches the passed in PVC for certain fields. Returns error
2078+
// if a match fails or a match is not possible given the state of the existing PVC
20752079
func (v *VRGInstance) validateExistingPVC(pvc *corev1.PersistentVolumeClaim) error {
20762080
existingPVC := &corev1.PersistentVolumeClaim{}
20772081
pvcNSName := types.NamespacedName{Name: pvc.Name, Namespace: pvc.Namespace}
@@ -2081,24 +2085,19 @@ func (v *VRGInstance) validateExistingPVC(pvc *corev1.PersistentVolumeClaim) err
20812085
return fmt.Errorf("failed to get existing PVC %s (%w)", pvcNSName.String(), err)
20822086
}
20832087

2084-
// If PVC not "Bound" return error
20852088
if existingPVC.Status.Phase != corev1.ClaimBound {
20862089
return fmt.Errorf("PVC %s exists and is not bound (phase: %s)", pvcNSName.String(), existingPVC.Status.Phase)
20872090
}
20882091

2089-
// If PVC is terminating return error
20902092
if !existingPVC.DeletionTimestamp.IsZero() {
20912093
return fmt.Errorf("existing bound PVC %s is being deleted", pvcNSName.String())
20922094
}
20932095

2094-
// Check match to the PV we expect PVC to be bound to
20952096
if existingPVC.Spec.VolumeName != pvc.Spec.VolumeName {
20962097
return fmt.Errorf("PVC %s exists and bound to a different PV %s than PV %s desired",
20972098
pvcNSName.String(), existingPVC.Spec.VolumeName, pvc.Spec.VolumeName)
20982099
}
20992100

2100-
// Should we check and see if PV in being deleted? Should we just treat it as exists
2101-
// and then we don't care if deletion takes place later, which is what we do now?
21022101
v.log.Info(fmt.Sprintf("PVC %s exists and bound to desired PV %s", pvcNSName.String(), existingPVC.Spec.VolumeName))
21032102

21042103
return nil

0 commit comments

Comments
 (0)