From c85807d0898c131c3653540129501b51451b8b88 Mon Sep 17 00:00:00 2001 From: "Md. Ishtiaq Islam" Date: Thu, 22 Aug 2024 19:20:51 +0600 Subject: [PATCH] Add disruption condition at target level Signed-off-by: Md. Ishtiaq Islam --- apis/constants.go | 14 ++++++++------ pkg/conditions/backupsession.go | 33 +++++++++++++++++++-------------- pkg/invoker/backupsession.go | 2 +- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/apis/constants.go b/apis/constants.go index d5cbe9f3e..146f46388 100644 --- a/apis/constants.go +++ b/apis/constants.go @@ -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 ( diff --git a/pkg/conditions/backupsession.go b/pkg/conditions/backupsession.go index 96a66b255..6eba06c7a 100644 --- a/pkg/conditions/backupsession.go +++ b/pkg/conditions/backupsession.go @@ -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{ @@ -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(), - }, - }, - }) -} diff --git a/pkg/invoker/backupsession.go b/pkg/invoker/backupsession.go index 707620f54..2c9ae9a03 100644 --- a/pkg/invoker/backupsession.go +++ b/pkg/invoker/backupsession.go @@ -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 } @@ -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)) {