Skip to content

Commit

Permalink
Add disruption condition at target level
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 22, 2024
1 parent 3fc7148 commit 6b2e6ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
13 changes: 7 additions & 6 deletions apis/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ 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"
LabelTargetAPIVersion = StashKey + "/target-api-version"
)

const (
Expand Down
33 changes: 19 additions & 14 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 Expand Up @@ -399,17 +418,3 @@ 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(),
},
},
})
}
2 changes: 1 addition & 1 deletion 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 Expand Up @@ -250,7 +251,6 @@ 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 || c.Type == v1beta1.BackupDisrupted {
if c.Status == metav1.ConditionFalse || c.Type == v1beta1.DeadlineExceeded {
return true, c.Message
}
}
Expand Down

0 comments on commit 6b2e6ee

Please sign in to comment.