Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add condition for backup disruption #223

Merged
merged 2 commits into from
Aug 23, 2024
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: 8 additions & 6 deletions apis/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ const (
)

const (
LabelApp = "app"
LabelInvokerType = StashKey + "/invoker-type"
LabelInvokerName = StashKey + "/invoker-name"
LabelTargetKind = StashKey + "/target-kind"
LabelTargetNamespace = StashKey + "/target-namespace"
LabelTargetName = StashKey + "/target-name"
LabelApp = "app"
LabelInvokerType = StashKey + "/invoker-type"
LabelInvokerName = StashKey + "/invoker-name"
LabelTargetKind = StashKey + "/target-kind"
LabelTargetNamespace = StashKey + "/target-namespace"
LabelTargetName = StashKey + "/target-name"
LabelTargetAPIGroup = StashKey + "/target-api-group"
LabelTargetAPIVersion = StashKey + "/target-api-version"
)

const (
Expand Down
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"
)
19 changes: 19 additions & 0 deletions pkg/conditions/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ func SetPostBackupHookExecutionSucceededToTrueWithMsg(session *invoker.BackupSes
})
}

func SetBackupDisruptedConditionToTrue(session *invoker.BackupSessionHandler, target v1beta1.TargetRef, err error) error {
return session.UpdateStatus(&v1beta1.BackupSessionStatus{
Targets: []v1beta1.BackupTargetStatus{
{
Ref: target,
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(),
},
},
},
},
})
}

func SetGlobalPreBackupHookSucceededConditionToFalse(session *invoker.BackupSessionHandler, hookErr error) error {
return session.UpdateStatus(&v1beta1.BackupSessionStatus{
Conditions: []kmapi.Condition{
Expand Down
1 change: 1 addition & 0 deletions pkg/invoker/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func upsertBackupHostStatus(cur, new []v1beta1.HostBackupStats) []v1beta1.HostBa
func calculateBackupTargetPhase(status v1beta1.BackupTargetStatus) v1beta1.TargetPhase {
if cutil.IsConditionFalse(status.Conditions, v1beta1.BackupExecutorEnsured) ||
cutil.IsConditionFalse(status.Conditions, v1beta1.PreBackupHookExecutionSucceeded) ||
cutil.IsConditionTrue(status.Conditions, v1beta1.BackupDisrupted) ||
cutil.IsConditionFalse(status.Conditions, v1beta1.PostBackupHookExecutionSucceeded) {
return v1beta1.TargetBackupFailed
}
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
Loading