@@ -2015,6 +2015,8 @@ func (v *VRGInstance) updateExistingPVForSync(pv *corev1.PersistentVolume) error
2015
2015
return nil
2016
2016
}
2017
2017
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
2018
2020
func (v * VRGInstance ) validateExistingPV (pv * corev1.PersistentVolume ) error {
2019
2021
log := v .log .WithValues ("PV" , pv .Name )
2020
2022
@@ -2072,6 +2074,8 @@ func (v *VRGInstance) validateExistingPV(pv *corev1.PersistentVolume) error {
2072
2074
return fmt .Errorf ("found existing PV (%s) not restored by Ramen and not matching with backed up PV" , existingPV .Name )
2073
2075
}
2074
2076
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
2075
2079
func (v * VRGInstance ) validateExistingPVC (pvc * corev1.PersistentVolumeClaim ) error {
2076
2080
existingPVC := & corev1.PersistentVolumeClaim {}
2077
2081
pvcNSName := types.NamespacedName {Name : pvc .Name , Namespace : pvc .Namespace }
@@ -2081,24 +2085,19 @@ func (v *VRGInstance) validateExistingPVC(pvc *corev1.PersistentVolumeClaim) err
2081
2085
return fmt .Errorf ("failed to get existing PVC %s (%w)" , pvcNSName .String (), err )
2082
2086
}
2083
2087
2084
- // If PVC not "Bound" return error
2085
2088
if existingPVC .Status .Phase != corev1 .ClaimBound {
2086
2089
return fmt .Errorf ("PVC %s exists and is not bound (phase: %s)" , pvcNSName .String (), existingPVC .Status .Phase )
2087
2090
}
2088
2091
2089
- // If PVC is terminating return error
2090
2092
if ! existingPVC .DeletionTimestamp .IsZero () {
2091
2093
return fmt .Errorf ("existing bound PVC %s is being deleted" , pvcNSName .String ())
2092
2094
}
2093
2095
2094
- // Check match to the PV we expect PVC to be bound to
2095
2096
if existingPVC .Spec .VolumeName != pvc .Spec .VolumeName {
2096
2097
return fmt .Errorf ("PVC %s exists and bound to a different PV %s than PV %s desired" ,
2097
2098
pvcNSName .String (), existingPVC .Spec .VolumeName , pvc .Spec .VolumeName )
2098
2099
}
2099
2100
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?
2102
2101
v .log .Info (fmt .Sprintf ("PVC %s exists and bound to desired PV %s" , pvcNSName .String (), existingPVC .Spec .VolumeName ))
2103
2102
2104
2103
return nil
0 commit comments