Set backupsession state to NEW

This commit is contained in:
Jean-Marc ANDRE 2023-02-07 17:12:43 +01:00
parent aba4ae4620
commit 888284017e
2 changed files with 23 additions and 4 deletions

View File

@ -35,8 +35,9 @@ const (
)
type TargetStatus struct {
Name string `json:"name"`
Kind string `json:"kind"`
BackupType `json:"backupType"`
TargetName string `json:"targetName"`
TargetKind `json:"targetKind"`
SessionState `json:"state"`
SnapshotId string `json:"snapshotId"`
StartTime *metav1.Time `json:"startTime"`

View File

@ -18,8 +18,10 @@ package controllers
import (
formolv1alpha1 "github.com/desmo999r/formol/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"
)
func (r *BackupSessionReconciler) isBackupOngoing(backupConf formolv1alpha1.BackupConfiguration) bool {
@ -36,10 +38,26 @@ 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, error) {
nextTargetIndex := len(backupSession.Status.Targets)
if nextTargetIndex < len(backupConf.Spec.Targets) {
nextTarget := backupConf.Spec.Targets[nextTargetIndex]
nextTargetStatus := formolv1alpha1.TargetStatus{
BackupType: nextTarget.BackupType,
TargetName: nextTarget.TargetName,
TargetKind: nextTarget.TargetKind,
SessionState: formolv1alpha1.New,
StartTime: &metav1.Time{Time: time.Now()},
Try: 1,
}
switch nextTarget.BackupType {
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
} else {
return nil, nil
}
return nil, nil
}