From ca84fa0d76aefa5b09b3c7a692886106f4e65e32 Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Thu, 10 Oct 2024 12:45:51 -0400 Subject: [PATCH] vrg: allow user to specify delay for checkhooks We don't have a checkhook implementation yet. Instead of running the check hook, we just delay the next group execution in the backup or recover sequence. The default delay is 5 seconds. If the recipe has an annotation with the key ramendr.openshift.io/check-hook-delay then the value of this annotation will determine the delay in seconds. Signed-off-by: Raghavendra Talur --- .../volumereplicationgroup_controller.go | 2 ++ internal/controller/vrg_kubeobjects.go | 7 ++++--- internal/controller/vrg_recipe.go | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/controller/volumereplicationgroup_controller.go b/internal/controller/volumereplicationgroup_controller.go index 5c1e2c66a..617ae3079 100644 --- a/internal/controller/volumereplicationgroup_controller.go +++ b/internal/controller/volumereplicationgroup_controller.go @@ -483,6 +483,7 @@ type VRGInstance struct { objectStorers map[string]cachedObjectStorer s3StoreAccessors []s3StoreAccessor result ctrl.Result + checkHookDelay int } const ( @@ -546,6 +547,7 @@ func (v *VRGInstance) processVRG() ctrl.Result { } v.log.Info("Recipe", "elements", v.recipeElements) + v.checkHookDelay = v.recipeElements.checkHookDelay if err := v.updatePVCList(); err != nil { return v.invalid(err, "Failed to process list of PVCs to protect", true) diff --git a/internal/controller/vrg_kubeobjects.go b/internal/controller/vrg_kubeobjects.go index 4394fe6b1..ffdd888f8 100644 --- a/internal/controller/vrg_kubeobjects.go +++ b/internal/controller/vrg_kubeobjects.go @@ -276,6 +276,7 @@ func (v *VRGInstance) kubeObjectsCaptureStartOrResume( ) } +// nolint: funlen func (v *VRGInstance) kubeObjectsGroupCapture( result *ctrl.Result, captureGroup kubeobjects.CaptureSpec, @@ -285,7 +286,7 @@ func (v *VRGInstance) kubeObjectsGroupCapture( log logr.Logger, ) (requestsCompletedCount int) { if captureGroup.Name == "CheckHookAsDelay" { - time.Sleep(5 * time.Second) + time.Sleep(time.Duration(v.checkHookDelay) * time.Second) requestsCompletedCount = len(v.s3StoreAccessors) return @@ -588,6 +589,7 @@ func (v *VRGInstance) getRecoverOrProtectRequest( } } +// nolint: funlen func (v *VRGInstance) kubeObjectsRecoveryStartOrResume( result *ctrl.Result, s3StoreAccessor s3StoreAccessor, sourceVrgNamespaceName, sourceVrgName string, @@ -599,9 +601,8 @@ func (v *VRGInstance) kubeObjectsRecoveryStartOrResume( requests := make([]kubeobjects.Request, len(groups)) for groupNumber, recoverGroup := range groups { - if recoverGroup.BackupName == "CheckHookAsDelay" { - time.Sleep(5 * time.Second) + time.Sleep(time.Duration(v.checkHookDelay) * time.Second) continue } diff --git a/internal/controller/vrg_recipe.go b/internal/controller/vrg_recipe.go index 5c46a50fb..b9af54daa 100644 --- a/internal/controller/vrg_recipe.go +++ b/internal/controller/vrg_recipe.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "os" + "strconv" "strings" "github.com/go-logr/logr" @@ -28,8 +29,11 @@ type RecipeElements struct { PvcSelector PvcSelector CaptureWorkflow []kubeobjects.CaptureSpec RecoverWorkflow []kubeobjects.RecoverSpec + checkHookDelay int } +const checkHookDelayAnnotation = "ramendr.openshift.io/check-hook-delay" + func captureWorkflowDefault(vrg ramen.VolumeReplicationGroup, ramenConfig ramen.RamenConfig) []kubeobjects.CaptureSpec { namespaces := []string{vrg.Namespace} @@ -97,6 +101,7 @@ func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.Volu ) } +// nolint: funlen func recipeVolumesAndOptionallyWorkflowsGet(ctx context.Context, reader client.Reader, vrg ramen.VolumeReplicationGroup, ramenConfig ramen.RamenConfig, log logr.Logger, recipeElements *RecipeElements, workflowsGet func(recipe.Recipe, *RecipeElements, ramen.VolumeReplicationGroup, ramen.RamenConfig) error, @@ -129,6 +134,17 @@ func recipeVolumesAndOptionallyWorkflowsGet(ctx context.Context, reader client.R return fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err) } + hookDelay := 5 + + if val, ok := recipe.Annotations[checkHookDelayAnnotation]; ok { + var err error + + hookDelay, err = strconv.Atoi(val) + if err != nil { + log.Error(err, "Failed to parse checkHookDelay annotation", "value", val) + } + } + if err := RecipeParametersExpand(&recipe, vrg.Spec.KubeObjectProtection.RecipeParameters, log); err != nil { return err } @@ -142,7 +158,8 @@ func recipeVolumesAndOptionallyWorkflowsGet(ctx context.Context, reader client.R } *recipeElements = RecipeElements{ - PvcSelector: selector, + PvcSelector: selector, + checkHookDelay: hookDelay, } if err := workflowsGet(recipe, recipeElements, vrg, ramenConfig); err != nil {