Skip to content

Commit ad07ebc

Browse files
committed
e2e: clean up namespaces after backup-failure tests to avoid interfering with subsequent tests
The test "should handle removal of MantleBackup in secondary k8s cluster during an incremental backup" was failing with a timeout. When the previous test (primary MantleBackup deletion scenario) finishes, a residual secondary MantleBackup is left behind in "waiting for export data" state because its primary was deleted before the upload completed. When the next test pauses RGW, the secondary reconciler gets blocked on S3 operations triggered by processing this residual MantleBackup, causing `kubectl delete --timeout=3m` issued against the current test's secondary MantleBackup to expire before finalizeSecondary could run. Delete both primary and secondary namespaces at the end of each backup-failure test via DeferCleanup, so that no residual MantleBackups remain when the next test starts. Signed-off-by: Kohya Shiozaki <kouyan120706@gmail.com>
1 parent 6fb2d62 commit ad07ebc

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

test/e2e/multik8s/backup_failure_test.go

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var _ = Describe("backup failure", Label("backup-failure"), func() {
1414
backupName := util.GetUniqueName("mb-")
1515

1616
SetupEnvironment(namespace)
17+
DeferCleanup(func() { TearDownEnvironment(namespace) })
1718

1819
// Pause the object storage to make backups fail.
1920
PauseObjectStorage(ctx)
@@ -55,6 +56,7 @@ var _ = Describe("backup failure", Label("backup-failure"), func() {
5556
restoreName := util.GetUniqueName("mr-")
5657

5758
SetupEnvironment(namespace)
59+
DeferCleanup(func() { TearDownEnvironment(namespace) })
5860

5961
// Pause the object storage to make backups fail.
6062
PauseObjectStorage(ctx)
@@ -106,6 +108,7 @@ var _ = Describe("backup failure", Label("backup-failure"), func() {
106108
restoreName0 := util.GetUniqueName("mr-")
107109

108110
SetupEnvironment(namespace)
111+
DeferCleanup(func() { TearDownEnvironment(namespace) })
109112

110113
// Create MantleBackup M0.
111114
CreatePVC(ctx, PrimaryK8sCluster, namespace, pvcName)
@@ -150,6 +153,11 @@ var _ = Describe("backup failure", Label("backup-failure"), func() {
150153

151154
It("should handle removal of MantleBackup in secondary k8s cluster during an incremental backup",
152155
func(ctx SpecContext) {
156+
// このテストが検証するシナリオ:
157+
// 「インクリメンタルバックアップの upload が進行中(S3 に届く前)に、
158+
// 管理者が secondary の MantleBackup を手動削除しても、
159+
// S3 が回復すれば最終的に正しい状態に戻れるか?」
160+
153161
namespace := util.GetUniqueName("ns-")
154162
pvcName := util.GetUniqueName("pvc-")
155163
backupName0 := util.GetUniqueName("mb-")
@@ -158,50 +166,69 @@ var _ = Describe("backup failure", Label("backup-failure"), func() {
158166
restoreName1 := util.GetUniqueName("mr-")
159167

160168
SetupEnvironment(namespace)
169+
DeferCleanup(func() { TearDownEnvironment(namespace) })
161170

162-
// Create MantleBackup M0.
171+
// [Step 1] フルバックアップ M0 を作成し、primary/secondary 両方への同期が
172+
// 完了するまで待つ。この時点で M0, M0' が SyncedToRemote 状態になっている。
163173
CreatePVC(ctx, PrimaryK8sCluster, namespace, pvcName)
164174
writtenDataHash0 := WriteRandomDataToPV(ctx, PrimaryK8sCluster, namespace, pvcName)
165175
CreateMantleBackup(PrimaryK8sCluster, namespace, pvcName, backupName0)
166176
WaitMantleBackupSynced(namespace, backupName0)
167177

168-
// Pause the object storage to make backups fail.
178+
// [Step 2] RGW(オブジェクトストレージ)を停止する。
179+
// これにより、以降の upload Job が S3 に届かず詰まるようになる。
180+
// defer で最終的に必ず再開されるが、テスト途中は停止したまま。
169181
PauseObjectStorage(ctx)
170182
defer ResumeObjectStorage(ctx)
171183

172-
// Create MantleBackup M1.
184+
// [Step 3] インクリメンタルバックアップ M1 を作成する。
185+
// primary 側では RBD スナップショット取得・エクスポートが行われるが、
186+
// upload は RGW 停止中のため S3 に届かず止まる。
173187
CreatePVC(ctx, PrimaryK8sCluster, namespace, pvcName)
174188
writtenDataHash1 := WriteRandomDataToPV(ctx, PrimaryK8sCluster, namespace, pvcName)
175189
CreateMantleBackup(PrimaryK8sCluster, namespace, pvcName, backupName1)
176190

177-
// Wait until an upload Job is created.
191+
// [Step 4] upload Job が作られるまで待つ。
192+
// この時点の状態:
193+
// primary: RBD スナップショット取得済み・エクスポート済み・upload Job 実行中(詰まってる)
194+
// S3: データはまだ届いていない
195+
// secondary: M1' の K8s オブジェクトは存在するが、import データが S3 にないため待機中
178196
WaitUploadJobCreated(ctx, PrimaryK8sCluster, namespace, backupName1, 0)
179197

180198
primaryMB1, err := GetMB(PrimaryK8sCluster, namespace, backupName1)
181199
Expect(err).NotTo(HaveOccurred())
182200
secondaryMB10, err := GetMB(SecondaryK8sCluster, namespace, backupName1)
183201
Expect(err).NotTo(HaveOccurred())
184202

185-
// Delete MantleBackup M1'.
203+
// [Step 5] secondary の M1' を手動削除する(管理者操作のシミュレーション)。
204+
// --timeout=3m で削除完了(finalizer 除去)まで待機する。
205+
// ※ システムが自動削除するわけではなく、テストが意図的に行う操作。
186206
DeleteMantleBackup(SecondaryK8sCluster, namespace, backupName1)
187207

188-
// Resume the object storage so that M1' will be deleted correctly after its finalization.
208+
// [Step 6] RGW を再開する。
209+
// M1' の finalization(finalizeSecondary)は deleteExportData=false で呼ばれるため
210+
// S3 アクセスは不要だが、その後 primary が M1' を再作成して upload を再試行するため
211+
// RGW が必要になる。
189212
ResumeObjectStorage(ctx)
190213

191-
// M1' should be re-created and synced.
214+
// [Step 7] M1' が再作成・同期されることを確認する。
215+
// primary の reconcile ループが CreateMantleBackup RPC を毎回呼ぶため、
216+
// M1' が削除されていても自動的に再作成される(冪等な動作)。
217+
// RGW が戻ったことで upload が完了し、secondary が import して SyncedToRemote になる。
192218
WaitMantleBackupSynced(namespace, backupName1)
193219

194-
// Make sure the PVC in the primary and secondary cluster DOES have a snapshot.
220+
// [Step 8] primary/secondary 両方の PVC に M1 相当のスナップショットが存在することを確認。
195221
EnsurePVCHasSnapshot(PrimaryK8sCluster, namespace, pvcName, backupName1)
196222
EnsurePVCHasSnapshot(SecondaryK8sCluster, namespace, pvcName, backupName1)
197223

198-
// Make sure we can restore correct data from M0, M0', M1, and M1'.
224+
// [Step 9] M0/M0'/M1/M1' の全てから正しいデータを復元できることを確認。
199225
EnsureCorrectRestoration(PrimaryK8sCluster, ctx, namespace, backupName0, restoreName0, writtenDataHash0)
200226
EnsureCorrectRestoration(SecondaryK8sCluster, ctx, namespace, backupName0, restoreName0, writtenDataHash0)
201227
EnsureCorrectRestoration(PrimaryK8sCluster, ctx, namespace, backupName1, restoreName1, writtenDataHash1)
202228
EnsureCorrectRestoration(SecondaryK8sCluster, ctx, namespace, backupName1, restoreName1, writtenDataHash1)
203229

204-
// Make sure all unnecessary resources are removed.
230+
// [Step 10] 一時リソース(import Job, export/import 用 PVC 等)が正しく削除されることを確認。
231+
// secondaryMB10: 削除された旧 M1'、secondaryMB11: 再作成された新 M1'
205232
secondaryMB11, err := GetMB(SecondaryK8sCluster, namespace, backupName1)
206233
Expect(err).NotTo(HaveOccurred())
207234
WaitTemporaryResourcesDeleted(ctx, primaryMB1, secondaryMB10)

test/e2e/multik8s/testutil/util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ func SetupEnvironment(namespace string) {
486486
}).Should(Succeed())
487487
}
488488

489+
func TearDownEnvironment(namespace string) {
490+
GinkgoHelper()
491+
Kubectl(PrimaryK8sCluster, nil, "delete", "namespace", namespace, "--ignore-not-found")
492+
Kubectl(SecondaryK8sCluster, nil, "delete", "namespace", namespace, "--ignore-not-found")
493+
}
494+
489495
func CreatePod(cluster int, namespace, podName, pvcName string) {
490496
GinkgoHelper()
491497
err := applyPodMountVolumeTemplate(cluster, namespace, podName, pvcName)

0 commit comments

Comments
 (0)