WIP: Have automatic backups before processing deletion
This MR will create and wait for a final backup of an instance before processing the deletion.
Part of issue: #90
Edited by Francisco Borges Aurindo Barros
Merge request reports
Activity
added 1 commit
- 475f1425 - Making the new Controller not actively wait per deletion job
101 if drupalSite.GetDeletionTimestamp() != nil { 102 if controllerutil.ContainsFinalizer(drupalSite, finalizerStr) { 103 backup, err := r.getFinalDrupalBackup(ctx, drupalSite, log) 104 if err != nil { 105 return ctrl.Result{}, err 106 } 107 if backup.Name == "" { 108 log.Info("No backup in place, making a backup before deletion") 109 r.makeFinalDrupalBackup(ctx, drupalSite, log) 110 return ctrl.Result{RequeueAfter: time.Minute * time.Duration(minutesWaitingForBackup)}, nil 111 } 112 if backup.Status.Phase == velerov1.BackupPhaseCompleted { 113 return r.cleanupDrupalSite(ctx, log, drupalSite, &backup) 114 } 115 if backup.Status.Phase == velerov1.BackupPhaseFailed { 116 log.Error(nil, "Final Backup before deletion has failed") changed this line in version 6 of the diff
requested review from @crdeoliv
- Resolved by Francisco Borges Aurindo Barros
- Resolved by Francisco Borges Aurindo Barros
- Resolved by Francisco Borges Aurindo Barros
- Resolved by Francisco Borges Aurindo Barros
920 920 }) 921 921 }) 922 922 }) 923 923 /* changed this line in version 7 of the diff
- Resolved by Francisco Borges Aurindo Barros
- Resolved by Francisco Borges Aurindo Barros
47 finalBackupLabelState = "drupalSite-FinalBackupState" 48 finalBackupStateOngoing = "deletionOngoing" 49 finalBackupStateProcessed = "applicationDeleted" 50 minutesWaitingForBackup = 2 51 ) 52 53 // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsites,verbs=get;list;watch;create;update;patch;delete 54 // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsites/status,verbs=get;update;patch 55 // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsites/finalizers,verbs=update 56 // +kubebuilder:rbac:groups=app,resources=deployments,verbs=* 57 58 // SetupWithManager adds a manager which watches the resources 59 func (r *DrupalSiteDeletionReconciler) SetupWithManager(mgr ctrl.Manager) error { 60 return ctrl.NewControllerManagedBy(mgr). 61 For(&webservicesv1a1.DrupalSite{}). 62 Watches(&source.Kind{Type: &appsv1.Deployment{}}, handler.EnqueueRequestsFromMapFunc( changed this line in version 6 of the diff
The goal was to trigger the backup upon deployment deletion (so it is guaranteed to have no actions after), but the
drupalsite
resource is kept while the backup is being done.This being said, the small amount of time difference, we can just work as well watching the change of state of the
drupalsite
resource.Updated to mirror the comment
132 backup.Labels[finalBackupLabelState] = finalBackupStateProcessed 133 if err := r.Update(ctx, backup, &client.UpdateOptions{}); err != nil { 134 return ctrl.Result{}, err 135 } 136 controllerutil.RemoveFinalizer(drp, finalizerStr) 137 if err := r.ensureNoBackupSchedule(ctx, drp, log); err != nil { 138 return ctrl.Result{}, err 139 } 140 return r.updateCRorFailReconcile(ctx, log, drp) 141 } 142 143 func (r *DrupalSiteDeletionReconciler) getFinalDrupalBackup(ctx context.Context, d *webservicesv1a1.DrupalSite, log logr.Logger) (velerov1.Backup, reconcileError) { 144 finalBackupList := &velerov1.BackupList{} 145 146 labelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{ 147 MatchLabels: map[string]string{"drupalSite": d.Name, finalBackupLabelState: finalBackupStateOngoing}, changed this line in version 6 of the diff
Please register or sign in to reply