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 ca84fa0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 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
7 changes: 4 additions & 3 deletions internal/controller/vrg_kubeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (v *VRGInstance) kubeObjectsCaptureStartOrResume(
)
}

// nolint: funlen
func (v *VRGInstance) kubeObjectsGroupCapture(
result *ctrl.Result,
captureGroup kubeobjects.CaptureSpec,
Expand All @@ -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
Expand Down Expand Up @@ -588,6 +589,7 @@ func (v *VRGInstance) getRecoverOrProtectRequest(
}
}

// nolint: funlen
func (v *VRGInstance) kubeObjectsRecoveryStartOrResume(
result *ctrl.Result, s3StoreAccessor s3StoreAccessor,
sourceVrgNamespaceName, sourceVrgName string,
Expand All @@ -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
}
Expand Down
19 changes: 18 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 @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down

0 comments on commit ca84fa0

Please sign in to comment.