From bd0f67d7fa80a0e45926232595f92f63ffb2b60d Mon Sep 17 00:00:00 2001 From: "Md. Ishtiaq Islam" Date: Thu, 19 Sep 2024 11:56:47 +0600 Subject: [PATCH] Add disruption condition at snapshot Signed-off-by: Md. Ishtiaq Islam --- apis/core/v1alpha1/backupsession_helpers.go | 7 ++++++- apis/core/v1alpha1/backupsession_types.go | 4 ++++ apis/core/v1alpha1/restoresession_helpers.go | 3 ++- apis/core/v1alpha1/restoresession_types.go | 3 +++ apis/storage/v1alpha1/snapshot_helpers.go | 3 ++- apis/storage/v1alpha1/snapshot_types.go | 3 +++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apis/core/v1alpha1/backupsession_helpers.go b/apis/core/v1alpha1/backupsession_helpers.go index edf3152e6..37c0b2775 100644 --- a/apis/core/v1alpha1/backupsession_helpers.go +++ b/apis/core/v1alpha1/backupsession_helpers.go @@ -64,7 +64,8 @@ func (b *BackupSession) CalculatePhase() BackupSessionPhase { b.failedToExecutePostBackupHooks() || b.failedToApplyRetentionPolicy() || b.verificationsFailed() || - b.sessionHistoryCleanupFailed()) { + b.sessionHistoryCleanupFailed() || + b.retentionPolicyDisrupted()) { return BackupSessionFailed } @@ -76,6 +77,10 @@ func (b *BackupSession) CalculatePhase() BackupSessionPhase { return BackupSessionRunning } +func (b *BackupSession) retentionPolicyDisrupted() bool { + return cutil.IsConditionTrue(b.Status.Conditions, TypeRetentionPolicyDisrupted) +} + func (b *BackupSession) sessionHistoryCleanupFailed() bool { return cutil.IsConditionFalse(b.Status.Conditions, TypeSessionHistoryCleaned) } diff --git a/apis/core/v1alpha1/backupsession_types.go b/apis/core/v1alpha1/backupsession_types.go index 9f0948396..8f7d20f08 100644 --- a/apis/core/v1alpha1/backupsession_types.go +++ b/apis/core/v1alpha1/backupsession_types.go @@ -231,6 +231,10 @@ const ( TypeSnapshotsEnsured = "SnapshotsEnsured" ReasonSuccessfullyEnsuredSnapshots = "SuccessfullyEnsuredSnapshots" ReasonFailedToEnsureSnapshots = "FailedToEnsureSnapshots" + + // TypeRetentionPolicyDisrupted indicates whether RetentionPolicy disrupted or not + TypeRetentionPolicyDisrupted = "RetentionPolicyDisrupted" + ReasonFailedToCompleteRetentionPolicyDueToDisruption = "FailedToCompleteRetentionPolicyDueToDisruption" ) //+kubebuilder:object:root=true diff --git a/apis/core/v1alpha1/restoresession_helpers.go b/apis/core/v1alpha1/restoresession_helpers.go index 11121df28..2277302a5 100644 --- a/apis/core/v1alpha1/restoresession_helpers.go +++ b/apis/core/v1alpha1/restoresession_helpers.go @@ -44,7 +44,8 @@ func (rs *RestoreSession) CalculatePhase() RestorePhase { if cutil.IsConditionTrue(rs.Status.Conditions, TypeMetricsPushed) && (cutil.IsConditionFalse(rs.Status.Conditions, TypePreRestoreHooksExecutionSucceeded) || cutil.IsConditionFalse(rs.Status.Conditions, TypePostRestoreHooksExecutionSucceeded) || - cutil.IsConditionFalse(rs.Status.Conditions, TypeRestoreExecutorEnsured)) { + cutil.IsConditionFalse(rs.Status.Conditions, TypeRestoreExecutorEnsured) || + cutil.IsConditionTrue(rs.Status.Conditions, TypeRestoreDisrupted)) { return RestoreFailed } diff --git a/apis/core/v1alpha1/restoresession_types.go b/apis/core/v1alpha1/restoresession_types.go index 56d028e50..8f55d49bb 100644 --- a/apis/core/v1alpha1/restoresession_types.go +++ b/apis/core/v1alpha1/restoresession_types.go @@ -370,6 +370,9 @@ const ( TypeRestoreTargetFound = "RestoreTargetFound" ReasonUnableToCheckTargetAvailability = "UnableToCheckTargetAvailability" + + TypeRestoreDisrupted = "RestoreDisrupted" + ReasonFailedToCompleteDueToDisruption = "FailedToCompleteDueToDisruption" ) //+kubebuilder:object:root=true diff --git a/apis/storage/v1alpha1/snapshot_helpers.go b/apis/storage/v1alpha1/snapshot_helpers.go index 96f968787..a17097ab4 100644 --- a/apis/storage/v1alpha1/snapshot_helpers.go +++ b/apis/storage/v1alpha1/snapshot_helpers.go @@ -34,7 +34,8 @@ func (_ Snapshot) CustomResourceDefinition() *apiextensions.CustomResourceDefini func (s *Snapshot) CalculatePhase() SnapshotPhase { if cutil.IsConditionFalse(s.Status.Conditions, TypeSnapshotMetadataUploaded) || - cutil.IsConditionFalse(s.Status.Conditions, TypeRecentSnapshotListUpdated) { + cutil.IsConditionFalse(s.Status.Conditions, TypeRecentSnapshotListUpdated) || + cutil.IsConditionTrue(s.Status.Conditions, TypeBackupDisrupted) { return SnapshotFailed } if s.GetComponentsPhase() == SnapshotPending { diff --git a/apis/storage/v1alpha1/snapshot_types.go b/apis/storage/v1alpha1/snapshot_types.go index c32513378..6cb08adb7 100644 --- a/apis/storage/v1alpha1/snapshot_types.go +++ b/apis/storage/v1alpha1/snapshot_types.go @@ -285,6 +285,9 @@ const ( TypeRecentSnapshotListUpdated = "RecentSnapshotListUpdated" ReasonFailedToUpdateRecentSnapshotList = "FailedToUpdateRecentSnapshotList" ReasonSuccessfullyUpdatedRecentSnapshotList = "SuccessfullyUpdatedRecentSnapshotList" + + TypeBackupDisrupted = "BackupDisrupted" + ReasonFailedToCompleteDueToDisruption = "FailedToCompleteDueToDisruption" ) //+kubebuilder:object:root=true