Moved BackupSession to Running. Set the first task to New.
This commit is contained in:
parent
888284017e
commit
8f180f5f52
@ -41,7 +41,7 @@ type TargetStatus struct {
|
||||
SessionState `json:"state"`
|
||||
SnapshotId string `json:"snapshotId"`
|
||||
StartTime *metav1.Time `json:"startTime"`
|
||||
Duration *metav1.Duration `json:"duration"`
|
||||
Duration *metav1.Duration `json:"duration,omitempty"`
|
||||
Try int `json:"try"`
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ type BackupSessionSpec struct {
|
||||
type BackupSessionStatus struct {
|
||||
SessionState `json:"state"`
|
||||
StartTime *metav1.Time `json:"startTime"`
|
||||
Targets []TargetStatus `json:"target"`
|
||||
Targets []TargetStatus `json:"target,omitempty"`
|
||||
Keep string `json:"keep"`
|
||||
}
|
||||
|
||||
|
||||
@ -99,6 +99,25 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
RequeueAfter: 30 * time.Second,
|
||||
}, nil
|
||||
}
|
||||
if nextTargetStatus := r.startNextTask(&backupSession, backupConf); nextTargetStatus != nil {
|
||||
r.Log.V(0).Info("New backup. Start the first task", "task", nextTargetStatus)
|
||||
backupSession.Status.SessionState = formolv1alpha1.Running
|
||||
if err := r.Status().Update(ctx, &backupSession); err != nil {
|
||||
r.Log.Error(err, "unable to update BackupSession status")
|
||||
}
|
||||
return ctrl.Result{}, err
|
||||
} else {
|
||||
r.Log.V(0).Info("No first target? That should not happen. Mark the backup has failed")
|
||||
backupSession.Status.SessionState = formolv1alpha1.Failure
|
||||
if err := r.Status().Update(ctx, &backupSession); err != nil {
|
||||
r.Log.Error(err, "unable to update BackupSession status")
|
||||
}
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
case formolv1alpha1.Running:
|
||||
// Backup ongoing. Check the status of the last backup task and decide what to do next.
|
||||
case formolv1alpha1.Failure:
|
||||
// Failed backup. Don't do anything anymore
|
||||
default:
|
||||
// BackupSession has just been created
|
||||
backupSession.Status.SessionState = formolv1alpha1.New
|
||||
|
||||
@ -38,7 +38,7 @@ func (r *BackupSessionReconciler) isBackupOngoing(backupConf formolv1alpha1.Back
|
||||
return len(backupSessionList.Items) > 0
|
||||
}
|
||||
|
||||
func (r *BackupSessionReconciler) startNextTask(backupSession formolv1alpha1.BackupSession, backupConf formolv1alpha1.BackupConfiguration) (*formolv1alpha1.TargetStatus, error) {
|
||||
func (r *BackupSessionReconciler) startNextTask(backupSession *formolv1alpha1.BackupSession, backupConf formolv1alpha1.BackupConfiguration) *formolv1alpha1.TargetStatus {
|
||||
nextTargetIndex := len(backupSession.Status.Targets)
|
||||
if nextTargetIndex < len(backupConf.Spec.Targets) {
|
||||
nextTarget := backupConf.Spec.Targets[nextTargetIndex]
|
||||
@ -51,13 +51,16 @@ func (r *BackupSessionReconciler) startNextTask(backupSession formolv1alpha1.Bac
|
||||
Try: 1,
|
||||
}
|
||||
switch nextTarget.BackupType {
|
||||
case formolv1alpha1.OnlineKind:
|
||||
r.Log.V(0).Info("Starts a new OnlineKind task", "target", nextTarget)
|
||||
case formolv1alpha1.JobKind:
|
||||
r.Log.V(0).Info("Starts a new JobKind task", "target", nextTarget)
|
||||
case formolv1alpha1.SnapshotKind:
|
||||
r.Log.V(0).Info("Starts a new SnapshotKind task", "target", nextTarget)
|
||||
}
|
||||
return &nextTargetStatus, nil
|
||||
backupSession.Status.Targets = append(backupSession.Status.Targets, nextTargetStatus)
|
||||
return &nextTargetStatus
|
||||
} else {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user