Compare commits

..

3 Commits

View File

@ -102,6 +102,11 @@ func (r *BackupSessionReconciler) StatusUpdate() error {
// The last task failed. We mark the backupsession as failed and we stop here. // The last task failed. We mark the backupsession as failed and we stop here.
log.V(0).Info("last backup task failed. Stop here", "targetStatus", currentTargetStatus) log.V(0).Info("last backup task failed. Stop here", "targetStatus", currentTargetStatus)
r.BackupSession.Status.SessionState = formolv1alpha1.Failure r.BackupSession.Status.SessionState = formolv1alpha1.Failure
log.V(1).Info("New BackupSession status", "status", r.BackupSession.Status.SessionState)
if err := r.Status().Update(ctx, r.BackupSession); err != nil {
log.Error(err, "unable to update BackupSession status")
return err
}
case formolv1alpha1.Running: case formolv1alpha1.Running:
// The current task is still running. Nothing to do // The current task is still running. Nothing to do
log.V(0).Info("task is still running", "targetStatus", currentTargetStatus) log.V(0).Info("task is still running", "targetStatus", currentTargetStatus)
@ -204,12 +209,12 @@ func (r *BackupSessionReconciler) StatusUpdate() error {
} }
} }
} }
}
log.V(1).Info("New BackupSession status", "status", r.BackupSession.Status.SessionState) log.V(1).Info("New BackupSession status", "status", r.BackupSession.Status.SessionState)
if err := r.Status().Update(ctx, r.BackupSession); err != nil { if err := r.Status().Update(ctx, r.BackupSession); err != nil {
log.Error(err, "unable to update BackupSession status") log.Error(err, "unable to update BackupSession status")
return err return err
} }
}
case formolv1alpha1.Deleted: case formolv1alpha1.Deleted:
for _, target := range r.BackupSession.Status.Targets { for _, target := range r.BackupSession.Status.Targets {
if target.SessionState != formolv1alpha1.Deleted { if target.SessionState != formolv1alpha1.Deleted {
@ -253,6 +258,7 @@ func (r *BackupSessionReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
ctx := context.Background() ctx := context.Background()
// your logic here // your logic here
time.Sleep(300 * time.Millisecond)
r.BackupSession = &formolv1alpha1.BackupSession{} r.BackupSession = &formolv1alpha1.BackupSession{}
if err := r.Get(ctx, req.NamespacedName, r.BackupSession); err != nil { if err := r.Get(ctx, req.NamespacedName, r.BackupSession); err != nil {
log.Error(err, "unable to get backupsession") log.Error(err, "unable to get backupsession")
@ -355,13 +361,14 @@ func (r *BackupSessionReconciler) CreateBackupJob(target formolv1alpha1.Target)
} }
// S3 backing storage // S3 backing storage
restic.Env = append(restic.Env, formolutils.ConfigureResticEnvVar(r.BackupConf, repo)...) restic.Env = append(restic.Env, formolutils.ConfigureResticEnvVar(r.BackupConf, repo)...)
jobTtl := JOBTTL
job := &batchv1.Job{ job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-%s-", r.BackupSession.Name, target.Name), GenerateName: fmt.Sprintf("%s-%s-", r.BackupSession.Name, target.Name),
Namespace: r.BackupConf.Namespace, Namespace: r.BackupConf.Namespace,
}, },
Spec: batchv1.JobSpec{ Spec: batchv1.JobSpec{
TTLSecondsAfterFinished: &JOBTTL, TTLSecondsAfterFinished: &jobTtl,
Template: corev1.PodTemplateSpec{ Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
InitContainers: []corev1.Container{}, InitContainers: []corev1.Container{},
@ -425,13 +432,14 @@ func (r *BackupSessionReconciler) deleteExternalResources() error {
} }
// create a job to delete the restic snapshot(s) with the backupsession name tag // create a job to delete the restic snapshot(s) with the backupsession name tag
if len(deleteSnapshots) > 0 { if len(deleteSnapshots) > 0 {
jobTtl := JOBTTL
job := &batchv1.Job{ job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("delete-%s-", r.BackupSession.Name), GenerateName: fmt.Sprintf("delete-%s-", r.BackupSession.Name),
Namespace: r.BackupSession.Namespace, Namespace: r.BackupSession.Namespace,
}, },
Spec: batchv1.JobSpec{ Spec: batchv1.JobSpec{
TTLSecondsAfterFinished: &JOBTTL, TTLSecondsAfterFinished: &jobTtl,
Template: corev1.PodTemplateSpec{ Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
InitContainers: []corev1.Container{}, InitContainers: []corev1.Container{},