diff --git a/controllers/backupsession_controller_helpers.go b/controllers/backupsession_controller_helpers.go index c32f86e..bb05727 100644 --- a/controllers/backupsession_controller_helpers.go +++ b/controllers/backupsession_controller_helpers.go @@ -50,7 +50,7 @@ func (r *BackupSessionReconciler) backupJob(tag string, target formolv1alpha1.Ta paths := []string{} for _, container := range target.Containers { for _, job := range container.Job { - if err = r.runFunction("backup-" + job.Name); err != nil { + if err = r.runFunction(*job.Backup); err != nil { r.Log.Error(err, "unable to run job") return } diff --git a/controllers/restoresession_controller_helper.go b/controllers/restoresession_controller_helper.go index 68473e3..dd0e05a 100644 --- a/controllers/restoresession_controller_helper.go +++ b/controllers/restoresession_controller_helper.go @@ -65,7 +65,7 @@ func (r *RestoreSessionReconciler) restoreJob(target formolv1alpha1.Target, targ } for _, container := range target.Containers { for _, job := range container.Job { - if err := r.runFunction("restore-" + job.Name); err != nil { + if err := r.runFunction(*job.Restore); err != nil { r.Log.Error(err, "unable to run restore job") return err } diff --git a/controllers/session.go b/controllers/session.go index 276e3ed..946d9cb 100644 --- a/controllers/session.go +++ b/controllers/session.go @@ -270,15 +270,18 @@ func (s Session) runTargetContainerChroot(runCmd string, args ...string) error { return nil } -func (s Session) runSteps(initializeSteps bool, target formolv1alpha1.Target) error { +type selectStep func(formolv1alpha1.Step) *string + +func (s Session) runSteps(target formolv1alpha1.Target, fn selectStep) error { // For every container listed in the target, run the initialization steps for _, container := range target.Containers { // Runs the steps one after the other for _, step := range container.Steps { - if (initializeSteps == true && step.Finalize != nil && *step.Finalize == true) || (initializeSteps == false && (step.Finalize == nil || step.Finalize != nil && *step.Finalize == false)) { - continue + if fn(step) != nil { + if err := s.runFunction(*fn(step)); err != nil { + return err + } } - return s.runFunction(step.Name) } } s.Log.V(0).Info("Done running steps") @@ -287,15 +290,19 @@ func (s Session) runSteps(initializeSteps bool, target formolv1alpha1.Target) er // Run the initializing steps in the INITIALIZING state of the controller // before actualy doing the backup in the RUNNING state -func (s Session) runFinalizeSteps(target formolv1alpha1.Target) error { +func (s Session) runInitializeSteps(target formolv1alpha1.Target) error { s.Log.V(0).Info("start to run the finalize steps it any") - return s.runSteps(false, target) + return s.runSteps(target, func(step formolv1alpha1.Step) *string { + return step.Initialize + }) } // Run the finalizing steps in the FINALIZE state of the controller // after the backup in the RUNNING state. // The finalize happens whatever the result of the backup. -func (s Session) runInitializeSteps(target formolv1alpha1.Target) error { +func (s Session) runFinalizeSteps(target formolv1alpha1.Target) error { s.Log.V(0).Info("start to run the initialize steps it any") - return s.runSteps(true, target) + return s.runSteps(target, func(step formolv1alpha1.Step) *string { + return step.Finalize + }) } diff --git a/formol b/formol index b7747b6..e73ef7c 160000 --- a/formol +++ b/formol @@ -1 +1 @@ -Subproject commit b7747b635d0253d39829d64ae96472da09c64297 +Subproject commit e73ef7c3f24ee612421b62963f443ff1a1e790dc