Skip to content

Commit

Permalink
actions/recipe: Fix handling of action cleanup errors
Browse files Browse the repository at this point in the history
Unify the recipe action to handle action cleanup errors
in the same way as Debos handles the cleanup functions.

Specifically:
- run all cleanup functions, even if a previous one failed,
- run cleanup functions in the reverse order to the action,
- report all errors during cleanup.

Fixes: 74df488 ("actions: Add recipe action")
Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc committed Jan 5, 2022
1 parent 20878a6 commit fba20b9
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions actions/recipe_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,17 @@ func (recipe *RecipeAction) Run(context *debos.DebosContext) error {
return nil
}

func (recipe *RecipeAction) Cleanup(context *debos.DebosContext) error {
func (recipe *RecipeAction) Cleanup(context *debos.DebosContext) (err error) {
for _, a := range recipe.Actions.Actions {
if err := a.Cleanup(&recipe.context); err != nil {
return err
}
defer func(action debos.Action) {
cleanup_err := action.Cleanup(context)

/* Cannot bubble multiple errors, so check for an error locally and
* return a generic error if the child recipe failed to cleanup. */
if defer_exitcode := debos.CheckError(context, cleanup_err, action, "Cleanup"); defer_exitcode != 0 {
err = errors.New("Child recipe failed")
}
}(a)
}

return nil
Expand All @@ -145,11 +151,17 @@ func (recipe *RecipeAction) PostMachine(context *debos.DebosContext) error {
return nil
}

func (recipe *RecipeAction) PostMachineCleanup(context *debos.DebosContext) error {
func (recipe *RecipeAction) PostMachineCleanup(context *debos.DebosContext) (err error) {
for _, a := range recipe.Actions.Actions {
if err := a.PostMachineCleanup(&recipe.context); err != nil {
return err
}
defer func(action debos.Action) {
cleanup_err := action.PostMachineCleanup(context)

/* Cannot bubble multiple errors, so check for an error locally and
* return a generic error if the child recipe failed to cleanup. */
if defer_exitcode := debos.CheckError(context, cleanup_err, action, "PostMachineCleanup"); defer_exitcode != 0 {
err = errors.New("Child recipe failed")
}
}(a)
}

return nil
Expand Down

0 comments on commit fba20b9

Please sign in to comment.