Skip to content

Commit

Permalink
vrg: allow user to specify delay for checkhooks
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
raghavendra-talur committed Oct 10, 2024
1 parent 63a3af2 commit ac0f3e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/controller/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ type VRGInstance struct {
objectStorers map[string]cachedObjectStorer
s3StoreAccessors []s3StoreAccessor
result ctrl.Result
checkHookDelay int
}

const (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/vrg_kubeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,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
Expand Down Expand Up @@ -601,7 +601,7 @@ func (v *VRGInstance) kubeObjectsRecoveryStartOrResume(
for groupNumber, recoverGroup := range groups {

if recoverGroup.BackupName == "CheckHookAsDelay" {
time.Sleep(5 * time.Second)
time.Sleep(time.Duration(v.checkHookDelay) * time.Second)

continue
}
Expand Down
16 changes: 15 additions & 1 deletion internal/controller/vrg_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"

"github.com/go-logr/logr"
Expand All @@ -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}

Expand Down Expand Up @@ -129,6 +133,15 @@ 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 {

Check failure on line 137 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

if statements should only be cuddled with assignments used in the if statement itself (wsl)

Check failure on line 137 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

if statements should only be cuddled with assignments used in the if statement itself (wsl)
var err error
hookDelay, err = strconv.Atoi(val)
if err != nil {

Check failure on line 140 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 140 in internal/controller/vrg_recipe.go

View workflow job for this annotation

GitHub Actions / Golangci Lint (.)

only one cuddle assignment allowed before if statement (wsl)
log.Error(err, "Failed to parse checkHookDelay annotation", "value", val)
}
}

if err := RecipeParametersExpand(&recipe, vrg.Spec.KubeObjectProtection.RecipeParameters, log); err != nil {
return err
}
Expand All @@ -142,7 +155,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 {
Expand Down

0 comments on commit ac0f3e8

Please sign in to comment.