Skip to content

Commit

Permalink
vrg: RecipeElementsGet should return RecipeElements
Browse files Browse the repository at this point in the history
Co-Authored-by: Annaraya Narasagond <[email protected]>
Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur and asn1809 committed Jan 7, 2025
1 parent dbd35f3 commit 15251f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
7 changes: 4 additions & 3 deletions internal/controller/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,10 @@ func (v *VRGInstance) processVRG() ctrl.Result {
}
}

if err := RecipeElementsGet(
v.ctx, v.reconciler.Client, *v.instance, *v.ramenConfig, v.log, &v.recipeElements,
); err != nil {
var err error

v.recipeElements, err = RecipeElementsGet(v.ctx, v.reconciler.Client, *v.instance, *v.ramenConfig, v.log)
if err != nil {
return v.invalid(err, "Failed to get recipe", false)
}

Expand Down
38 changes: 23 additions & 15 deletions internal/controller/vrg_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,35 @@ func GetPVCSelector(ctx context.Context, reader client.Reader, vrg ramen.VolumeR
ramenConfig ramen.RamenConfig,
log logr.Logger,
) (PvcSelector, error) {
var recipeElements RecipeElements
recipeElements, err := RecipeElementsGet(ctx, reader, vrg, ramenConfig, log)
if err != nil {
return recipeElements.PvcSelector, err
}

return recipeElements.PvcSelector, RecipeElementsGet(
ctx, reader, vrg, ramenConfig, log, &recipeElements)
return recipeElements.PvcSelector, nil
}

func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.VolumeReplicationGroup,
ramenConfig ramen.RamenConfig, log logr.Logger, recipeElements *RecipeElements,
) error {
ramenConfig ramen.RamenConfig, log logr.Logger,
) (RecipeElements, error) {
var recipeElements RecipeElements

if vrg.Spec.KubeObjectProtection == nil {
*recipeElements = RecipeElements{
recipeElements = RecipeElements{
PvcSelector: getPVCSelector(vrg, ramenConfig, nil, nil),
}

return nil
return recipeElements, nil
}

if vrg.Spec.KubeObjectProtection.RecipeRef == nil {
*recipeElements = RecipeElements{
recipeElements = RecipeElements{
PvcSelector: getPVCSelector(vrg, ramenConfig, nil, nil),
CaptureWorkflow: captureWorkflowDefault(vrg, ramenConfig),
RecoverWorkflow: recoverWorkflowDefault(vrg, ramenConfig),
}

return nil
return recipeElements, nil
}

recipeNamespacedName := types.NamespacedName{
Expand All @@ -113,11 +117,11 @@ func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.Volu

recipe := recipe.Recipe{}
if err := reader.Get(ctx, recipeNamespacedName, &recipe); err != nil {
return fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err)
return recipeElements, fmt.Errorf("recipe %v get error: %w", recipeNamespacedName.String(), err)
}

if err := RecipeParametersExpand(&recipe, vrg.Spec.KubeObjectProtection.RecipeParameters, log); err != nil {
return err
return recipeElements, fmt.Errorf("recipe %v parameters expansion error: %w", recipeNamespacedName.String(), err)
}

var selector PvcSelector
Expand All @@ -128,15 +132,19 @@ func RecipeElementsGet(ctx context.Context, reader client.Reader, vrg ramen.Volu
recipe.Spec.Volumes.LabelSelector)
}

*recipeElements = RecipeElements{
recipeElements = RecipeElements{
PvcSelector: selector,
}

if err := recipeWorkflowsGet(recipe, recipeElements, vrg, ramenConfig); err != nil {
return err
if err := recipeWorkflowsGet(recipe, &recipeElements, vrg, ramenConfig); err != nil {
return recipeElements, fmt.Errorf("recipe %v workflows get error: %w", recipeNamespacedName.String(), err)
}

if err := recipeNamespacesValidate(recipeElements, vrg, ramenConfig); err != nil {
return recipeElements, fmt.Errorf("recipe %v namespaces validation error: %w", recipeNamespacedName.String(), err)
}

return recipeNamespacesValidate(*recipeElements, vrg, ramenConfig)
return recipeElements, nil
}

func RecipeParametersExpand(recipe *recipe.Recipe, parameters map[string][]string,
Expand Down

0 comments on commit 15251f0

Please sign in to comment.