Skip to content

Commit

Permalink
Add condition for backup disruption
Browse files Browse the repository at this point in the history
Signed-off-by: Md. Ishtiaq Islam <ishtiaq@appscode.com>
  • Loading branch information
ishtiaqhimel committed Aug 23, 2024
1 parent 36516c2 commit 49ed0e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apis/stash/v1beta1/backup_session_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ const (

// DeadlineExceeded indicates whether the session deadline was exceeded or not
DeadlineExceeded = "DeadlineExceeded"

// BackupDisrupted indicates whether the backup was disrupted or not
BackupDisrupted = "BackupDisrupted"
)

// =========================== Condition Reasons =======================
Expand Down Expand Up @@ -276,4 +279,6 @@ const (
FailedToExecutePostBackupHook = "FailedToExecutePostBackupHook"

FailedToCompleteWithinDeadline = "FailedToCompleteWithinDeadline"

FailedToCompleteDueToDisruption = "FailedToCompleteDueToDisruption"
)
14 changes: 14 additions & 0 deletions pkg/conditions/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,17 @@ func SetBackupDeadlineExceededConditionToTrue(session *invoker.BackupSessionHand
},
})
}

func SetBackupDisruptedConditionToTrue(session *invoker.BackupSessionHandler, err error) error {
return session.UpdateStatus(&v1beta1.BackupSessionStatus{
Conditions: []kmapi.Condition{
{
Type: v1beta1.BackupDisrupted,
Status: metav1.ConditionTrue,
Reason: v1beta1.FailedToCompleteDueToDisruption,
Message: fmt.Sprintf("Failed to complete backup. Reason: %v.", err.Error()),
LastTransitionTime: metav1.Now(),
},
},
})
}
1 change: 1 addition & 0 deletions pkg/invoker/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func calculateBackupSessionPhase(status *v1beta1.BackupSessionStatus) v1beta1.Ba

if cutil.IsConditionTrue(status.Conditions, v1beta1.MetricsPushed) &&
(cutil.IsConditionTrue(status.Conditions, v1beta1.DeadlineExceeded) ||
cutil.IsConditionTrue(status.Conditions, v1beta1.BackupDisrupted) ||
cutil.IsConditionFalse(status.Conditions, v1beta1.BackupHistoryCleaned) ||
cutil.IsConditionFalse(status.Conditions, v1beta1.GlobalPreBackupHookSucceeded) ||
cutil.IsConditionFalse(status.Conditions, v1beta1.GlobalPostBackupHookSucceeded)) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/invoker/restoresession.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func checkRestoreFailureInHostStatus(status []v1beta1.HostRestoreStats) (bool, s

func checkFailureInConditions(conditions []kmapi.Condition) (bool, string) {
for _, c := range conditions {
if c.Status == metav1.ConditionFalse || c.Type == v1beta1.DeadlineExceeded {
if c.Status == metav1.ConditionFalse || c.Type == v1beta1.DeadlineExceeded || c.Type == v1beta1.BackupDisrupted {
return true, c.Message
}
}
Expand Down

0 comments on commit 49ed0e8

Please sign in to comment.