Skip to content

Commit 5e2fa13

Browse files
committed
Continue executing only if there is nothing to restore
Signed-off-by: Benamar Mekhissi <[email protected]> (cherry picked from commit b057d15)
1 parent 838d29b commit 5e2fa13

4 files changed

+32
-22
lines changed

controllers/protectedvolumereplicationgrouplist_controller_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func protectedVrgListExpectInclude(protectedVrgList *ramen.ProtectedVolumeReplic
9595
vrgsExpected []ramen.VolumeReplicationGroup,
9696
) {
9797
vrgsStatusStateUpdate(protectedVrgList.Status.Items, vrgsExpected)
98+
Expect(protectedVrgList.Status.Items).To(ContainElements(vrgsExpected))
9899
}
99100

100101
func vrgsStatusStateUpdate(vrgsS3, vrgsK8s []ramen.VolumeReplicationGroup) {

controllers/volumereplicationgroup_controller.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -578,28 +578,32 @@ func (v *VRGInstance) validateVRGMode() error {
578578
return nil
579579
}
580580

581-
func (v *VRGInstance) clusterDataRestore(result *ctrl.Result) error {
581+
func (v *VRGInstance) clusterDataRestore(result *ctrl.Result) (int, error) {
582582
v.log.Info("Restoring PVs and PVCs")
583583

584-
err := v.restorePVsAndPVCsForVolSync()
584+
numRestoredForVS, err := v.restorePVsAndPVCsForVolSync()
585585
if err != nil {
586586
v.log.Info("VolSync PV/PVC restore failed")
587587

588-
return fmt.Errorf("failed to restore PV/PVC for VolSync (%w)", err)
588+
return numRestoredForVS, fmt.Errorf("failed to restore PV/PVC for VolSync (%w)", err)
589589
}
590590

591-
err = v.restorePVsAndPVCsForVolRep(result)
591+
numRestoredForVR, err := v.restorePVsAndPVCsForVolRep(result)
592592
if err != nil {
593593
v.log.Info("VolRep PV/PVC restore failed")
594594

595-
return fmt.Errorf("failed to restore PV/PVC for VolRep (%w)", err)
595+
return numRestoredForVS + numRestoredForVR, fmt.Errorf("failed to restore PV/PVC for VolRep (%w)", err)
596596
}
597597

598598
// Only after both succeed, we mark ClusterDataReady as true
599599
msg := "Restored PVs and PVCs"
600+
if numRestoredForVS+numRestoredForVR == 0 {
601+
msg = "Nothing to restore"
602+
}
603+
600604
setVRGClusterDataReadyCondition(&v.instance.Status.Conditions, v.instance.Generation, msg)
601605

602-
return nil
606+
return numRestoredForVS + numRestoredForVR, nil
603607
}
604608

605609
func (v *VRGInstance) listPVCsByVrgPVCSelector() (*corev1.PersistentVolumeClaimList, error) {
@@ -852,12 +856,16 @@ func (v *VRGInstance) processAsPrimary() ctrl.Result {
852856

853857
if v.shouldRestoreClusterData() {
854858
v.result.Requeue = true
855-
if err := v.clusterDataRestore(&v.result); err != nil {
859+
860+
numOfRestoredRes, err := v.clusterDataRestore(&v.result)
861+
if err != nil {
856862
return v.clusterDataError(err, "Failed to restore PVs/PVCs", v.result)
857863
}
858864

859-
// Restore success -- update status and requeue
860-
return v.updateVRGConditionsAndStatus(v.result)
865+
// Save status and requeue if we restored any resources (PV/PVCs). Otherwise, continue
866+
if numOfRestoredRes != 0 {
867+
return v.updateVRGConditionsAndStatus(v.result)
868+
}
861869
}
862870

863871
v.reconcileAsPrimary()

controllers/vrg_volrep.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -1817,30 +1817,31 @@ func (v *VRGInstance) s3KeyPrefix() string {
18171817
return S3KeyPrefix(v.namespacedName)
18181818
}
18191819

1820-
func (v *VRGInstance) restorePVsAndPVCsForVolRep(result *ctrl.Result) error {
1820+
func (v *VRGInstance) restorePVsAndPVCsForVolRep(result *ctrl.Result) (int, error) {
18211821
v.log.Info("Restoring VolRep PVs and PVCs")
18221822

18231823
if len(v.instance.Spec.S3Profiles) == 0 {
18241824
v.log.Info("No S3 profiles configured")
18251825

18261826
result.Requeue = true
18271827

1828-
return fmt.Errorf("no S3Profiles configured")
1828+
return 0, fmt.Errorf("no S3Profiles configured")
18291829
}
18301830

18311831
v.log.Info(fmt.Sprintf("Restoring PVs and PVCs to this managed cluster. ProfileList: %v", v.instance.Spec.S3Profiles))
18321832

1833-
if err := v.restorePVsAndPVCsFromS3(result); err != nil {
1833+
count, err := v.restorePVsAndPVCsFromS3(result)
1834+
if err != nil {
18341835
errMsg := fmt.Sprintf("failed to restore PVs and PVCs using profile list (%v)", v.instance.Spec.S3Profiles)
18351836
v.log.Info(errMsg)
18361837

1837-
return fmt.Errorf("%s: %w", errMsg, err)
1838+
return 0, fmt.Errorf("%s: %w", errMsg, err)
18381839
}
18391840

1840-
return nil
1841+
return count, nil
18411842
}
18421843

1843-
func (v *VRGInstance) restorePVsAndPVCsFromS3(result *ctrl.Result) error {
1844+
func (v *VRGInstance) restorePVsAndPVCsFromS3(result *ctrl.Result) (int, error) {
18441845
err := errors.New("s3Profiles empty")
18451846
NoS3 := false
18461847

@@ -1891,16 +1892,16 @@ func (v *VRGInstance) restorePVsAndPVCsFromS3(result *ctrl.Result) error {
18911892

18921893
v.log.Info(fmt.Sprintf("Restored %d PVs and %d PVCs using profile %s", pvCount, pvcCount, s3ProfileName))
18931894

1894-
return v.kubeObjectsRecover(result, s3StoreProfile, objectStore)
1895+
return pvCount + pvcCount, v.kubeObjectsRecover(result, s3StoreProfile, objectStore)
18951896
}
18961897

18971898
if NoS3 {
1898-
return nil
1899+
return 0, nil
18991900
}
19001901

19011902
result.Requeue = true
19021903

1903-
return err
1904+
return 0, err
19041905
}
19051906

19061907
func (v *VRGInstance) restorePVsFromObjectStore(objectStore ObjectStorer, s3ProfileName string) (int, error) {

controllers/vrg_volsync.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
)
1717

18-
func (v *VRGInstance) restorePVsAndPVCsForVolSync() error {
18+
func (v *VRGInstance) restorePVsAndPVCsForVolSync() (int, error) {
1919
v.log.Info("VolSync: Restoring VolSync PVs")
2020

2121
if len(v.instance.Spec.VolSync.RDSpec) == 0 {
2222
v.log.Info("No RDSpec entries. There are no PVCs to restore")
2323
// No ReplicationDestinations (i.e. no PVCs) to restore
24-
return nil
24+
return 0, nil
2525
}
2626

2727
numPVsRestored := 0
@@ -59,12 +59,12 @@ func (v *VRGInstance) restorePVsAndPVCsForVolSync() error {
5959
}
6060

6161
if numPVsRestored != len(v.instance.Spec.VolSync.RDSpec) {
62-
return fmt.Errorf("failed to restore all PVCs using RDSpec (%v)", v.instance.Spec.VolSync.RDSpec)
62+
return numPVsRestored, fmt.Errorf("failed to restore all PVCs using RDSpec (%v)", v.instance.Spec.VolSync.RDSpec)
6363
}
6464

6565
v.log.Info("Success restoring VolSync PVs", "Total", numPVsRestored)
6666

67-
return nil
67+
return numPVsRestored, nil
6868
}
6969

7070
func (v *VRGInstance) reconcileVolSyncAsPrimary(finalSyncPrepared *bool) (requeue bool) {

0 commit comments

Comments
 (0)