Skip to content

Commit

Permalink
DNM: Fix for migtools#58
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Pryc <[email protected]>
  • Loading branch information
mpryc committed Oct 25, 2024
1 parent ba72f89 commit a402174
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 8 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/nonadminbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
NonAdminBackupPhaseBackingOff NonAdminBackupPhase = "BackingOff"
// NonAdminBackupPhaseCreated - Velero Backup was created. The Phase will not have additional informations about the Backup.
NonAdminBackupPhaseCreated NonAdminBackupPhase = "Created"
// NonAdminBackupPhaseDeletion - Velero Backup is pending deletion. The Phase will not have additional informations about the Backup.
NonAdminBackupPhaseDeletion NonAdminBackupPhase = "Deletion"
)

// NonAdminBackupSpec defines the desired state of NonAdminBackup
Expand All @@ -43,6 +45,10 @@ type NonAdminBackupSpec struct {
// +optional
// +kubebuilder:validation:Enum=trace;debug;info;warning;error;fatal;panic
LogLevel string `json:"logLevel,omitempty"`

// DeleteBackup tells the controller to remove created Velero Backup.
// +optional
DeleteBackup bool `json:"deleteBackup,omitempty"`
}

// VeleroBackup contains information of the related Velero backup object.
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/nonadmincontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ type NonAdminCondition string
const (
NonAdminConditionAccepted NonAdminCondition = "Accepted"
NonAdminConditionQueued NonAdminCondition = "Queued"
NonAdminConditionDeletion NonAdminCondition = "Deletion"
)
4 changes: 4 additions & 0 deletions config/crd/bases/nac.oadp.openshift.io_nonadminbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ spec:
type: string
type: array
type: object
deleteBackup:
description: DeleteBackup tells the controller to remove created Velero
Backup.
type: boolean
logLevel:
description: NonAdminBackup log level (use debug for the most logging,
leave unset for default)
Expand Down
30 changes: 27 additions & 3 deletions docs/design/nab_and_nar_status_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Those are are the possible values for phase:
| New | *NonAdminBackup/NonAdminRestore* resource was accepted by the NAB/NAR Controller, but it has not yet been validated by the NAB/NAR Controller |
| BackingOff | *NonAdminBackup/NonAdminRestore* resource was invalidated by the NAB/NAR Controller, due to invalid Spec. NAB/NAR Controller will not reconcile the object further, until user updates it |
| Created | *NonAdminBackup/NonAdminRestore* resource was validated by the NAB/NAR Controller and Velero *Backup/restore* was created. The Phase will not have additional information about the *Backup/Restore* run |
| Deletion | *NonAdminBackup/NonAdminRestore* resource has been marked for deletion. The NAB/NAR Controller will delete the corresponding Velero *Backup/Restore* if it exists. Once this deletion completes, the *NonAdminBackup/NonAdminRestore* object itself will also be removed |

### Conditions

Expand Down Expand Up @@ -123,7 +124,7 @@ It is similar for a NonAdminRestore.
```mermaid
%%{init: {'theme':'neutral'}}%%
graph
flowchart TD


predicateUpdateNabEvent{{predicate: Accepted **update** event NAB}};
Expand All @@ -137,6 +138,8 @@ requeueFalseTerminalErr[\"Requeue: false, Terminal error"/];

reconcileStartAcceptedPredicate[/Reconcile start\];

questionIsMarkedForDeletion{"Is NAB marked for deletion ?"};
questionIsFinalizerForDeletionSet{"Is NonAdminBackup finalizer set ?"};
questionPhaseStatusSetToNew{"Is status.phase: **New** ?"};
questionConditionAcceptedTrue{"Is status.conditions[Accepted]: **True** ?"};
questionIsNabValid{"Is NonAdminBackup Spec valid ?"};
Expand All @@ -152,26 +155,47 @@ questionSuccessWithNoRequeue{"Success ?"};
questionSuccessGetVB{"Error ?"};
questionGetSingleVB{"Is Single Velero Backup found ?"};
questionNabStatusUpdateFromVB{"Does NAB Object status requires update ?"};
questionPhaseStatusSetToDeletion{"Is status.phase: **Deletion** ?"};
questionDoesVeleroObjectExists("Does Velero Object with corresponding status.VeleroBackup.NameUUID exist ?")

createVBObject{{"Create New Velero Backup Object"}};

deleteVeleroObject{{"Delete Velero Backup Object"}};
deleteNonAdminBackupObject{{"Delete Non Admin Backup Object"}}

getUUIDMatchingVeleroBackup("Get Velero Backup with label openshift.io/oadp-nab-origin-nameuuid matching status.VeleroBackup.NameUUID");

statusPhaseSetToNew["Set status.phase to: **New**"];
statusPhaseSetToDeletion["Set status.phase to: **Deletion**"];
statusPhaseStatusSetToBackingOff["Set status.phase: **BackingOff**
and status.conditions[Accepted]: **False** ?"];
statusConditionSetAcceptedToTrue["Set status.conditions[Accepted] to **True**"];
statusPhaseStatusSetToCreated["Set status.phase: **Created**
and status.conditions[BackupScheduled]: **True** ?"];
statusSetVeleroBackupUUID["Generate a NameUUID and set it as status.VeleroBackup.NameUUID"];
statusNabStatusUpdateFromVB["Update NonAdminBackup status from Velero Backup"];
setFinalizerOnNab["Set finalizer on NonAdminBackup"]

predicateCreateNabEvent --> reconcileStartAcceptedPredicate;
predicateUpdateNabEvent --> reconcileStartAcceptedPredicate;
predicateUpdateVBEvent --> reconcileStartAcceptedPredicate;

reconcileStartAcceptedPredicate --> questionPhaseStatusSetToNew;
reconcileStartAcceptedPredicate --> questionIsMarkedForDeletion;
questionIsMarkedForDeletion -- Yes --> questionIsFinalizerForDeletionSet;
questionIsFinalizerForDeletionSet -- No --> setFinalizerOnNab;
setFinalizerOnNab --> questionSuccess;

questionIsFinalizerForDeletionSet -- Yes --> questionPhaseStatusSetToDeletion;

questionPhaseStatusSetToDeletion -- No --> statusPhaseSetToDeletion;
statusPhaseSetToDeletion --> questionSuccess;
questionPhaseStatusSetToDeletion -- Yes --> questionDoesVeleroObjectExists;
questionDoesVeleroObjectExists -- No --> deleteNonAdminBackupObject;
questionDoesVeleroObjectExists -- Yes --> deleteVeleroObject;
deleteVeleroObject --> questionSuccess;
deleteNonAdminBackupObject --> questionSuccessWithNoRequeue;

questionIsMarkedForDeletion -- No --> questionPhaseStatusSetToNew;

questionPhaseStatusSetToNew -- No --> statusPhaseSetToNew;
questionPhaseStatusSetToNew -- Yes --> questionIsNabValid;

Expand Down
1 change: 1 addition & 0 deletions internal/common/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
NabOriginNamespaceAnnotation = "openshift.io/oadp-nab-origin-namespace"
NabOriginNameUUIDLabel = "openshift.io/oadp-nab-origin-nameuuid"
NarOriginNameUUIDLabel = "openshift.io/oadp-nar-origin-nameuuid"
NabFinalizerName = "nonadminbackup.oadp.openshift.io/finalizer"
)

// Common environment variables for the Non Admin Controller
Expand Down
Loading

0 comments on commit a402174

Please sign in to comment.