Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions api/v1/mantlebackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ type MantleBackupStatus struct {
}

const (
BackupConditionReadyToUse = "ReadyToUse"
BackupConditionSyncedToRemote = "SyncedToRemote"
BackupConditionVerified = "Verified"
BackupConditionSnapshotCaptured = "SnapshotCaptured"
BackupConditionSyncedToRemote = "SyncedToRemote"
BackupConditionVerified = "Verified"

// Reasons for ConditionReadyToUse
ConditionReasonReadyToUseNoProblem = "NoProblem"
// Reasons for ConditionSnapshotCaptured
ConditionReasonSnapshotCapturedNoProblem = "NoProblem"
// Reasons for ConditionSyncedToRemote
ConditionReasonSyncedToRemoteNoProblem = "NoProblem"
// Reasons for ConditionVerified
Expand Down Expand Up @@ -93,8 +93,8 @@ type MantleBackupList struct {
Items []MantleBackup `json:"items"`
}

func (m *MantleBackup) IsReady() bool {
return meta.IsStatusConditionTrue(m.Status.Conditions, BackupConditionReadyToUse)
func (m *MantleBackup) IsSnapshotCaptured() bool {
return meta.IsStatusConditionTrue(m.Status.Conditions, BackupConditionSnapshotCaptured)
}

func (m *MantleBackup) IsSynced() bool {
Expand Down
4 changes: 2 additions & 2 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ spec:
expire: 2w # when the MantleBackup should expire.
status:
conditions:
# The corresponding backup data is ready to use if `status` is "True"
- type: "ReadyToUse"
# The corresponding backup data has been captured if `status` is "True".
- type: "SnapshotCaptured"
status: "True"
```

Expand Down
60 changes: 30 additions & 30 deletions internal/controller/mantlebackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (r *MantleBackupReconciler) reconcileLocalBackup(ctx context.Context, backu
return ctrl.Result{}, err
}

if !backup.IsReady() {
if !backup.IsSnapshotCaptured() {
if err := r.provisionRBDSnapshot(ctx, backup, target); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -519,14 +519,14 @@ func (r *MantleBackupReconciler) reconcileAsSecondary(ctx context.Context, backu
return ctrl.Result{}, err
}

if !backup.IsReady() {
if !backup.IsSnapshotCaptured() {
result, err := r.startImport(ctx, backup, target)
if err != nil || !result.IsZero() {
return result, err
}
}

if backup.IsReady() && !backup.IsVerifiedTrue() && !backup.IsVerifiedFalse() {
if backup.IsSnapshotCaptured() && !backup.IsVerifiedTrue() && !backup.IsVerifiedFalse() {
if err := r.verify(ctx, backup); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -590,7 +590,7 @@ func (r *MantleBackupReconciler) replicate(
return ctrl.Result{}, err
}

if prepareResult.isSecondaryMantleBackupReadyToUse {
if prepareResult.isSecondaryMantleBackupSnapshotCaptured {
if err := r.updateMantleBackupCondition(
ctx, backup,
mantlev1.BackupConditionSyncedToRemote,
Expand Down Expand Up @@ -888,7 +888,7 @@ func (r *MantleBackupReconciler) provisionRBDSnapshot(
}

meta.SetStatusCondition(&backup.Status.Conditions, metav1.Condition{
Type: mantlev1.BackupConditionReadyToUse, Status: metav1.ConditionTrue, Reason: mantlev1.ConditionReasonReadyToUseNoProblem})
Type: mantlev1.BackupConditionSnapshotCaptured, Status: metav1.ConditionTrue, Reason: mantlev1.ConditionReasonSnapshotCapturedNoProblem})

return nil
}); err != nil {
Expand Down Expand Up @@ -987,9 +987,9 @@ func (r *MantleBackupReconciler) finalizeSecondary(
}

type dataSyncPrepareResult struct {
isIncremental bool // NOTE: The value is forcibly set to false if isSecondaryMantleBackupReadyToUse is true.
isSecondaryMantleBackupReadyToUse bool
diffFrom *mantlev1.MantleBackup // non-nil value iff isIncremental is true.
isIncremental bool // NOTE: The value is forcibly set to false if isSecondaryMantleBackupSnapshotCaptured is true.
isSecondaryMantleBackupSnapshotCaptured bool
diffFrom *mantlev1.MantleBackup // non-nil value iff isIncremental is true.
}

func (r *MantleBackupReconciler) prepareForDataSynchronization(
Expand Down Expand Up @@ -1023,23 +1023,23 @@ func (r *MantleBackupReconciler) prepareForDataSynchronization(
return nil, fmt.Errorf("secondary MantleBackup not found: %s, %s",
backup.GetName(), backup.GetNamespace())
}
isSecondaryMantleBackupReadyToUse := secondaryBackup.IsReady()
isSecondaryMantleBackupSnapshotCaptured := secondaryBackup.IsSnapshotCaptured()

if isSecondaryMantleBackupReadyToUse {
if isSecondaryMantleBackupSnapshotCaptured {
return &dataSyncPrepareResult{
isIncremental: false,
isSecondaryMantleBackupReadyToUse: true,
diffFrom: nil,
isIncremental: false,
isSecondaryMantleBackupSnapshotCaptured: true,
diffFrom: nil,
}, nil
}

if syncMode, ok := backup.GetAnnotations()[annotSyncMode]; ok {
switch syncMode {
case syncModeFull:
return &dataSyncPrepareResult{
isIncremental: false,
isSecondaryMantleBackupReadyToUse: isSecondaryMantleBackupReadyToUse,
diffFrom: nil,
isIncremental: false,
isSecondaryMantleBackupSnapshotCaptured: isSecondaryMantleBackupSnapshotCaptured,
diffFrom: nil,
}, nil
case syncModeIncremental:
diffFromName, ok := backup.GetAnnotations()[annotDiffFrom]
Expand All @@ -1057,9 +1057,9 @@ func (r *MantleBackupReconciler) prepareForDataSynchronization(
}

return &dataSyncPrepareResult{
isIncremental: true,
isSecondaryMantleBackupReadyToUse: isSecondaryMantleBackupReadyToUse,
diffFrom: &diffFrom,
isIncremental: true,
isSecondaryMantleBackupSnapshotCaptured: isSecondaryMantleBackupSnapshotCaptured,
diffFrom: &diffFrom,
}, nil
default:
return nil, fmt.Errorf("unknown sync mode: %s", syncMode)
Expand All @@ -1080,9 +1080,9 @@ func (r *MantleBackupReconciler) prepareForDataSynchronization(
isIncremental := (diffFrom != nil)

return &dataSyncPrepareResult{
isIncremental: isIncremental,
isSecondaryMantleBackupReadyToUse: isSecondaryMantleBackupReadyToUse,
diffFrom: diffFrom,
isIncremental: isIncremental,
isSecondaryMantleBackupSnapshotCaptured: isSecondaryMantleBackupSnapshotCaptured,
diffFrom: diffFrom,
}, nil
}

Expand All @@ -1106,7 +1106,7 @@ func searchForDiffOriginMantleBackup(
if !ok {
continue
}
if !primaryBackup.IsReady() || !secondaryBackup.IsReady() {
if !primaryBackup.IsSnapshotCaptured() || !secondaryBackup.IsSnapshotCaptured() {
continue
}
if !primaryBackup.DeletionTimestamp.IsZero() || !secondaryBackup.DeletionTimestamp.IsZero() {
Expand Down Expand Up @@ -2030,8 +2030,8 @@ func (r *MantleBackupReconciler) startImport(
return ctrl.Result{}, fmt.Errorf("failed to unlock the volume: %w", err)
}

if err := r.markSecondaryReadyToUse(ctx, backup, target); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to mark the secondary as ready to use: %w", err)
if err := r.markSecondarySnapshotCaptured(ctx, backup, target); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to mark the secondary as snapshot captured: %w", err)
}

return ctrl.Result{}, nil
Expand Down Expand Up @@ -2821,8 +2821,8 @@ func (r *MantleBackupReconciler) createOrUpdateImportJob(
return err
}

// markSecondaryReadyToUse marks the MantleBackup ReadyToUse as True.
func (r *MantleBackupReconciler) markSecondaryReadyToUse(
// markSecondarySnapshotCaptured marks the MantleBackup SnapshotCaptured as True.
func (r *MantleBackupReconciler) markSecondarySnapshotCaptured(
ctx context.Context,
backup *mantlev1.MantleBackup,
snapshotTarget *snapshotTarget,
Expand All @@ -2838,13 +2838,13 @@ func (r *MantleBackupReconciler) markSecondaryReadyToUse(
return fmt.Errorf("failed to find imported RBD snapshot: %w", err)
}

// Update the status of the MantleBackup to set True to the ReadyToUse condition.
// Update the status of the MantleBackup to set True to the SnapshotCaptured condition.
if err := updateStatus(ctx, r.Client, backup, func() error {
backup.Status.SnapID = &snapshot.Id
meta.SetStatusCondition(&backup.Status.Conditions, metav1.Condition{
Type: mantlev1.BackupConditionReadyToUse,
Type: mantlev1.BackupConditionSnapshotCaptured,
Status: metav1.ConditionTrue,
Reason: mantlev1.ConditionReasonReadyToUseNoProblem,
Reason: mantlev1.ConditionReasonSnapshotCapturedNoProblem,
})

return nil
Expand Down
Loading
Loading