diff --git a/controllers/vrg_volrep_test.go b/controllers/vrg_volrep_test.go index b216e678c..fd48a7cdd 100644 --- a/controllers/vrg_volrep_test.go +++ b/controllers/vrg_volrep_test.go @@ -1443,10 +1443,6 @@ func (v *vrgTest) kubeObjectProtectionValidate() *ramendrv1alpha1.VolumeReplicat } func kubeObjectProtectionValidate(tests []*vrgTest) { - if true { - return // TODO re-enable - } - protectedVrgList := protectedVrgListCreateAndStatusWait("protectedvrglist-vrg-"+tests[0].uniqueID, vrgS3ProfileNumber) vrgs := make([]ramendrv1alpha1.VolumeReplicationGroup, len(tests)) diff --git a/controllers/vrg_vrgobject.go b/controllers/vrg_vrgobject.go index 6f3378f40..cb6f2e27b 100644 --- a/controllers/vrg_vrgobject.go +++ b/controllers/vrg_vrgobject.go @@ -4,26 +4,21 @@ package controllers import ( - "time" - ramen "github.com/ramendr/ramen/api/v1alpha1" "github.com/ramendr/ramen/controllers/util" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" ) -var vrgLastUploadTime = map[string]metav1.Time{} +var vrgLastUploadVersion = map[string]string{} func (v *VRGInstance) vrgObjectProtect(result *ctrl.Result, s3StoreAccessors []s3StoreAccessor) { + vrg := v.instance log := v.log - if lastUploadTime, ok := vrgLastUploadTime[v.namespacedName]; ok { - const maxVRGProtectionInterval = time.Minute - - // Throttle VRG protection if this call is more recent than maxVRGProtectionInterval. - if shouldThrottleVRGProtection(lastUploadTime, maxVRGProtectionInterval) { - log.Info("VRG already protected recently. Throttling...") + if lastUploadVersion, ok := vrgLastUploadVersion[v.namespacedName]; ok { + if vrg.ResourceVersion == lastUploadVersion { + log.Info("VRG resource version unchanged, skip S3 upload", "version", vrg.ResourceVersion) return } @@ -61,19 +56,13 @@ func (v *VRGInstance) vrgObjectProtectThrottled(result *ctrl.Result, s3StoreAcce log1.Info("VRG Kube object protected") - vrgLastUploadTime[v.namespacedName] = metav1.Now() - + vrgLastUploadVersion[v.namespacedName] = vrg.ResourceVersion v.vrgObjectProtected = newVRGClusterDataProtectedCondition(vrg.Generation, clusterDataProtectedTrueMessage) } success() } -func shouldThrottleVRGProtection(lastUploadTime metav1.Time, maxVRGProtectionTime time.Duration) bool { - // Throttle VRG protection if this call is more recent than MaxVRGProtectionTime. - return time.Now().Before(lastUploadTime.Add(maxVRGProtectionTime)) -} - const vrgS3ObjectNameSuffix = "a" func VrgObjectProtect(objectStorer ObjectStorer, vrg ramen.VolumeReplicationGroup) error {