Skip to content

Instantly share code, notes, and snippets.

@jortel
Last active May 14, 2019 15:09
Show Gist options
  • Save jortel/3b7d3d1aab049f7353f41535f06d9a95 to your computer and use it in GitHub Desktop.
Save jortel/3b7d3d1aab049f7353f41535f06d9a95 to your computer and use it in GitHub Desktop.
Suggest the Task report its "phase" instead of returning complete (bool). This provides information to the caller to determine based on what's being watched vs polled whether a reconcile requeue is needed. As a side benefit, the Task.Run() can consolidate logging. By doing this, the responsibility of doing the requeue is delegated to the controller which understands reconciles and watches etc. The Task simply reports a rich state.
-----------------------
// Phase
const (
Created = "Created"
RestartRestic = "RestartRestic"
WaitingOnResticPod = "WaitingOnResticPod"
BackupStarted = "BackupStarted"
BackupCompleted = "BackupCompleted"
BackupFailed = "BackupFailed"
WaitingOnBackupReplication = "WaitingOnBackupReplication"
RestoreStarted = "RestoreStarted"
RestoreCompleted = "RestoreCompleted"
RestoredFailed = "RestoreFailed"
Completed = "Completed"
)
type Task struct {
...
Phase string
}
func (t *Task) Run() error {
defer t.Log.Info(
"Task:",
"phase",
t.Phase,
"owner",
t.Owner.GetName(),
"restore",
t.Restore.Name)
...
The individual logging messages can be remoted.
In the controller migrate.go & stage.go:
// Now returns requeue(bool), err
func (r *ReconcileMigMigration) migrate(migration *migapi.MigMigration) (bool, error) {
requeue := false
// Run
...
err := task.Run()
if err != nil {
return reconcile.Result{}, err
}
switch task.Phase {
case Completed:
log.Info("Migration completed.", "name", migration.Name)
migration.MarkAsCompleted()
err = r.Update(context.TODO(), migration)
if err != nil {
return false, err
}
case WaitingOnResticPod:
requeue = true
}
return requeue, nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment