diff --git a/apis/stash/v1alpha1/validator.go b/apis/stash/v1alpha1/validator.go index ef66f3757..ede3bcbaf 100644 --- a/apis/stash/v1alpha1/validator.go +++ b/apis/stash/v1alpha1/validator.go @@ -89,5 +89,15 @@ func (r Repository) IsValid() error { return fmt.Errorf("wipe out operation is not supported for B2 backend") } } + + if r.Spec.Backend.Local != nil && r.Spec.Backend.Local.MountPath != "" { + parts := strings.Split(r.Spec.Backend.Local.MountPath, "/") + if len(parts) >= 2 && parts[1] == "stash" { + return fmt.Errorf("\n\t" + + "Error: Invalid `mountPath` specification for local backend.\n\t" + + "Reason: We have put `stash` binary in the root directory. Hence, you can not use `/stash` or `/stash/*` as `mountPath` \n\t" + + "Hints: Use `/stash-backup` or anything else except the forbidden ones as `mountPath`.") + } + } return nil } diff --git a/pkg/controller/backup.go b/pkg/controller/backup.go index fe728f2f6..32952865c 100644 --- a/pkg/controller/backup.go +++ b/pkg/controller/backup.go @@ -418,7 +418,7 @@ func (c *StashController) handleAutoBackupResourcesCreationSuccess(ref *core.Obj c.kubeClient, eventer.EventSourceAutoBackupHandler, ref, - core.EventTypeWarning, + core.EventTypeNormal, eventer.EventReasonAutoBackupResourcesCreationSucceeded, fmt.Sprintf("Successfully created auto backup resources for %s %s/%s.", ref.Kind, ref.Namespace, ref.Name), ) @@ -448,7 +448,7 @@ func (c *StashController) handleAutoBackupResourcesDeletionSuccess(ref *core.Obj c.kubeClient, eventer.EventSourceAutoBackupHandler, ref, - core.EventTypeWarning, + core.EventTypeNormal, eventer.EventReasonAutoBackupResourcesDeletionSucceeded, fmt.Sprintf("Successfully deleted auto backup resources for %s %s/%s.", ref.Kind, ref.Namespace, ref.Name), ) diff --git a/pkg/util/job.go b/pkg/util/job.go index e7e9aaa6a..bc704fc69 100644 --- a/pkg/util/job.go +++ b/pkg/util/job.go @@ -220,7 +220,7 @@ func NewPVCRestorerJob(rs *api_v1beta1.RestoreSession, repository *api_v1alpha1. Image: image.ToContainerImage(), Args: append([]string{ "restore", - "--restore-session=" + rs.Name, + "--restoresession=" + rs.Name, "--restore-model=job", "--secret-dir=" + StashSecretMountDir, fmt.Sprintf("--enable-cache=%v", !rs.Spec.TempDir.DisableCaching), diff --git a/test/e2e/advance-configuration/runtimesettings.go b/test/e2e/advance-configuration/runtimesettings.go index 82d02b2c3..6a2a7d6de 100644 --- a/test/e2e/advance-configuration/runtimesettings.go +++ b/test/e2e/advance-configuration/runtimesettings.go @@ -17,8 +17,6 @@ limitations under the License. package advance_configuration import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -40,10 +38,7 @@ var _ = Describe("Advanced Configuration", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -55,7 +50,7 @@ var _ = Describe("Advanced Configuration", func() { Context("With NICE and IONICE", func() { It("should Backup & Restore successfully", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment1-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -99,7 +94,7 @@ var _ = Describe("Advanced Configuration", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, func(restore *v1beta1.RestoreSession) { + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume, func(restore *v1beta1.RestoreSession) { restore.Spec.RuntimeSettings = ofst.RuntimeSettings{ Container: &ofst.ContainerRuntimeSettings{ Nice: &ofst.NiceSettings{ diff --git a/test/e2e/auto-backup/daemonset.go b/test/e2e/auto-backup/daemonset.go index 540b4b11c..834c4c172 100644 --- a/test/e2e/auto-backup/daemonset.go +++ b/test/e2e/auto-backup/daemonset.go @@ -41,10 +41,7 @@ var _ = Describe("Auto-Backup", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -56,7 +53,7 @@ var _ = Describe("Auto-Backup", func() { return map[string]string{ v1beta1.KeyBackupBlueprint: backupBlueprintName, v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, - v1beta1.KeyVolumeMounts: framework.TestSourceDataVolumeMount, + v1beta1.KeyVolumeMounts: framework.TestSourceVolumeAndMount, } } @@ -66,11 +63,11 @@ var _ = Describe("Auto-Backup", func() { It("should backup successfully", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -113,7 +110,7 @@ var _ = Describe("Auto-Backup", func() { f.AppendToCleanupList(bb) // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -150,7 +147,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -179,11 +176,11 @@ var _ = Describe("Auto-Backup", func() { Context("Add inappropriate annotation to Target", func() { It("should fail to create AutoBackup resources", func() { // Create BackupBlueprint - _, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + _, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -200,11 +197,11 @@ var _ = Describe("Auto-Backup", func() { }) It("should fail BackupSession for adding inappropriate TargetPath/MountPath", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data diff --git a/test/e2e/auto-backup/deployment.go b/test/e2e/auto-backup/deployment.go index 67ef4db3c..595e62b56 100644 --- a/test/e2e/auto-backup/deployment.go +++ b/test/e2e/auto-backup/deployment.go @@ -41,10 +41,7 @@ var _ = Describe("Auto-Backup", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -56,7 +53,7 @@ var _ = Describe("Auto-Backup", func() { return map[string]string{ v1beta1.KeyBackupBlueprint: backupBlueprintName, v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, - v1beta1.KeyVolumeMounts: framework.TestSourceDataVolumeMount, + v1beta1.KeyVolumeMounts: framework.TestSourceVolumeAndMount, } } @@ -65,11 +62,11 @@ var _ = Describe("Auto-Backup", func() { Context("Success Case", func() { It("should backup successfully", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("deployment1-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDaemonSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -112,7 +109,7 @@ var _ = Describe("Auto-Backup", func() { f.AppendToCleanupList(bb) // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("deployment2-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -149,7 +146,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("deployment3-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -178,11 +175,11 @@ var _ = Describe("Auto-Backup", func() { Context("Add inappropriate annotation to Target", func() { It("should fail to create AutoBackup resources", func() { // Create BackupBlueprint - _, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + _, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("deployment4-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -198,11 +195,11 @@ var _ = Describe("Auto-Backup", func() { }) It("should fail BackupSession for adding inappropriate TargetPath/MountPath", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("deployment5-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data diff --git a/test/e2e/auto-backup/pvc.go b/test/e2e/auto-backup/pvc.go index ffca557d5..5d9554b31 100644 --- a/test/e2e/auto-backup/pvc.go +++ b/test/e2e/auto-backup/pvc.go @@ -41,10 +41,7 @@ var _ = Describe("Auto-Backup", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -64,11 +61,11 @@ var _ = Describe("Auto-Backup", func() { It("should backup successfully", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForPVC(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForPVC(framework.PvcBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Create a PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("pvc1-%s", f.App())) + pvc, err := f.CreateNewPVC(framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -115,7 +112,7 @@ var _ = Describe("Auto-Backup", func() { f.AppendToCleanupList(bb) // Create a PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("pvc2-%s", f.App())) + pvc, err := f.CreateNewPVC(framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -156,7 +153,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) // Create a PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("pvc3-%s", f.App())) + pvc, err := f.CreateNewPVC(framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -189,11 +186,11 @@ var _ = Describe("Auto-Backup", func() { Context("Add inappropriate annotation to Target", func() { It("should fail to create AutoBackup resources", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForPVC(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForPVC(framework.PvcBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Create a PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("pvc4-%s", f.App())) + pvc, err := f.CreateNewPVC(framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod diff --git a/test/e2e/auto-backup/replicaset.go b/test/e2e/auto-backup/replicaset.go index 0d767c948..bc4ff5d3d 100644 --- a/test/e2e/auto-backup/replicaset.go +++ b/test/e2e/auto-backup/replicaset.go @@ -41,10 +41,7 @@ var _ = Describe("Auto-Backup", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -56,7 +53,7 @@ var _ = Describe("Auto-Backup", func() { return map[string]string{ v1beta1.KeyBackupBlueprint: backupBlueprintName, v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, - v1beta1.KeyVolumeMounts: framework.TestSourceDataVolumeMount, + v1beta1.KeyVolumeMounts: framework.TestSourceVolumeAndMount, } } @@ -66,11 +63,11 @@ var _ = Describe("Auto-Backup", func() { It("should success auto-backup for the ReplicaSet", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("rs1-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -113,7 +110,7 @@ var _ = Describe("Auto-Backup", func() { f.AppendToCleanupList(bb) // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("rs2-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -150,7 +147,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("rs3-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -179,11 +176,11 @@ var _ = Describe("Auto-Backup", func() { Context("Add inappropriate annotation to Target", func() { It("should fail to create AutoBackup resources", func() { // Create BackupBlueprint - _, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + _, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("rs4-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -199,11 +196,11 @@ var _ = Describe("Auto-Backup", func() { }) It("should fail BackupSession for adding inappropriate TargetPath/MountPath", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("rs5-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -229,9 +226,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionFailed)) }) - }) }) }) - }) diff --git a/test/e2e/auto-backup/replicationcontroller.go b/test/e2e/auto-backup/replicationcontroller.go index 0d0256904..e0209d472 100644 --- a/test/e2e/auto-backup/replicationcontroller.go +++ b/test/e2e/auto-backup/replicationcontroller.go @@ -41,10 +41,7 @@ var _ = Describe("Auto-Backup", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -56,7 +53,7 @@ var _ = Describe("Auto-Backup", func() { return map[string]string{ v1beta1.KeyBackupBlueprint: backupBlueprintName, v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, - v1beta1.KeyVolumeMounts: framework.TestSourceDataVolumeMount, + v1beta1.KeyVolumeMounts: framework.TestSourceVolumeAndMount, } } @@ -66,11 +63,11 @@ var _ = Describe("Auto-Backup", func() { It("should backup successfully", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("rc1-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -113,7 +110,7 @@ var _ = Describe("Auto-Backup", func() { f.AppendToCleanupList(bb) // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("rc2-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -150,7 +147,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("rc3-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -179,11 +176,11 @@ var _ = Describe("Auto-Backup", func() { Context("Add inappropriate annotation to Target", func() { It("should fail auto-backup for adding inappropriate BackupBlueprint annotation in ReplicationController", func() { // Create BackupBlueprint - _, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + _, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("rc4-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -199,11 +196,11 @@ var _ = Describe("Auto-Backup", func() { }) It("should fail BackupSession for adding inappropriate TargetPath/MountPath ReplicationController", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("rc5-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data diff --git a/test/e2e/auto-backup/statefulset.go b/test/e2e/auto-backup/statefulset.go index 1a30ea61a..98241280e 100644 --- a/test/e2e/auto-backup/statefulset.go +++ b/test/e2e/auto-backup/statefulset.go @@ -41,10 +41,7 @@ var _ = Describe("Auto-Backup", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -56,7 +53,7 @@ var _ = Describe("Auto-Backup", func() { return map[string]string{ v1beta1.KeyBackupBlueprint: backupBlueprintName, v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, - v1beta1.KeyVolumeMounts: framework.TestSourceDataVolumeMount, + v1beta1.KeyVolumeMounts: framework.TestSourceVolumeAndMount, } } @@ -66,11 +63,11 @@ var _ = Describe("Auto-Backup", func() { It("should success auto-backup for the StatefulSet", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("ss1-%s", f.App()), int32(1)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -113,7 +110,7 @@ var _ = Describe("Auto-Backup", func() { f.AppendToCleanupList(bb) // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("ss2-%s", f.App()), int32(1)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -150,7 +147,7 @@ var _ = Describe("Auto-Backup", func() { Expect(err).NotTo(HaveOccurred()) // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("ss3-%s", f.App()), int32(1)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -179,11 +176,11 @@ var _ = Describe("Auto-Backup", func() { Context("Add inappropriate annotation to Target", func() { It("Should fail auto-backup for adding inappropriate BackupBlueprint annotation in StatefulSet", func() { // Create BackupBlueprint - _, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + _, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("ss4-%s", f.App()), int32(1)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -199,11 +196,11 @@ var _ = Describe("Auto-Backup", func() { }) It("should fail BackupSession for adding inappropriate TargetPath/MountPath StatefulSet", func() { // Create BackupBlueprint - bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) + bb, err := f.CreateBackupBlueprintForWorkload(framework.WorkloadBackupBlueprint) Expect(err).NotTo(HaveOccurred()) // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("ss5-%s", f.App()), int32(1)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -232,5 +229,4 @@ var _ = Describe("Auto-Backup", func() { }) }) }) - }) diff --git a/test/e2e/backend/azure.go b/test/e2e/backend/azure.go index ff2320d69..d26fcbc69 100644 --- a/test/e2e/backend/azure.go +++ b/test/e2e/backend/azure.go @@ -17,8 +17,6 @@ limitations under the License. package backend import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("Azure Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -52,7 +47,7 @@ var _ = Describe("Azure Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from Azure backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -83,7 +78,7 @@ var _ = Describe("Azure Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -103,7 +98,7 @@ var _ = Describe("Azure Backend", func() { Context("WipeOut Repository", func() { It("should cleanup data from remote repository", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -145,7 +140,7 @@ var _ = Describe("Azure Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -176,7 +171,7 @@ var _ = Describe("Azure Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -196,7 +191,7 @@ var _ = Describe("Azure Backend", func() { Context("Backup/Restore with maxConnection", func() { It("should backup/restore with maxConnection", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -227,7 +222,7 @@ var _ = Describe("Azure Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/backend/b2.go b/test/e2e/backend/b2.go index 96667a353..6efd640e5 100644 --- a/test/e2e/backend/b2.go +++ b/test/e2e/backend/b2.go @@ -17,8 +17,6 @@ limitations under the License. package backend import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("B2 Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -52,7 +47,7 @@ var _ = Describe("B2 Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from B2 backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -83,7 +78,7 @@ var _ = Describe("B2 Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -103,7 +98,7 @@ var _ = Describe("B2 Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -134,7 +129,7 @@ var _ = Describe("B2 Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -154,7 +149,7 @@ var _ = Describe("B2 Backend", func() { Context("Backup/Restore with maxConnection", func() { It("should backup/restore with maxConnection", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -185,7 +180,7 @@ var _ = Describe("B2 Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/backend/gcs.go b/test/e2e/backend/gcs.go index 0b0e8da06..80ff0a36f 100644 --- a/test/e2e/backend/gcs.go +++ b/test/e2e/backend/gcs.go @@ -17,8 +17,6 @@ limitations under the License. package backend import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("GCS Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -52,7 +47,7 @@ var _ = Describe("GCS Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from GCS backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -83,7 +78,7 @@ var _ = Describe("GCS Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -103,7 +98,7 @@ var _ = Describe("GCS Backend", func() { Context("WipeOut Repository", func() { It("should cleanup data from remote repository", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -145,7 +140,7 @@ var _ = Describe("GCS Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -176,7 +171,7 @@ var _ = Describe("GCS Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -196,7 +191,7 @@ var _ = Describe("GCS Backend", func() { Context("Backup/Restore with maxConnection", func() { It("should backup/restore with maxConnection", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -227,7 +222,7 @@ var _ = Describe("GCS Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/backend/local.go b/test/e2e/backend/local.go index 20dcc8f58..e7341c171 100644 --- a/test/e2e/backend/local.go +++ b/test/e2e/backend/local.go @@ -17,8 +17,6 @@ limitations under the License. package backend import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -46,10 +44,7 @@ var _ = Describe("Local Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -64,7 +59,7 @@ var _ = Describe("Local Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from Local backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -95,7 +90,7 @@ var _ = Describe("Local Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -115,7 +110,7 @@ var _ = Describe("Local Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -146,7 +141,7 @@ var _ = Describe("Local Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -168,7 +163,7 @@ var _ = Describe("Local Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from Local backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1), func(dp *apps.Deployment) { + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume, func(dp *apps.Deployment) { dp.Spec.Template.Spec.Containers[0].SecurityContext = &core.SecurityContext{ Privileged: types.BoolP(true), RunAsUser: types.Int64P(int64(0)), @@ -213,7 +208,7 @@ var _ = Describe("Local Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -233,7 +228,7 @@ var _ = Describe("Local Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1), func(dp *apps.Deployment) { + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume, func(dp *apps.Deployment) { dp.Spec.Template.Spec.Containers[0].SecurityContext = &core.SecurityContext{ Privileged: types.BoolP(true), RunAsUser: types.Int64P(int64(0)), @@ -278,7 +273,7 @@ var _ = Describe("Local Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -300,7 +295,7 @@ var _ = Describe("Local Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from Local backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -339,7 +334,7 @@ var _ = Describe("Local Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -359,7 +354,7 @@ var _ = Describe("Local Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -398,7 +393,7 @@ var _ = Describe("Local Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/backend/rest.go b/test/e2e/backend/rest.go index c5fd45fda..744a92f9b 100644 --- a/test/e2e/backend/rest.go +++ b/test/e2e/backend/rest.go @@ -17,7 +17,6 @@ limitations under the License. package backend import ( - "fmt" "net" "stash.appscode.dev/stash/apis" @@ -39,10 +38,7 @@ var _ = Describe("Rest Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -59,7 +55,7 @@ var _ = Describe("Rest Backend", func() { It("should backup/restore in/from Rest backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -90,7 +86,7 @@ var _ = Describe("Rest Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -116,7 +112,7 @@ var _ = Describe("Rest Backend", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -147,7 +143,7 @@ var _ = Describe("Rest Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -173,7 +169,7 @@ var _ = Describe("Rest Backend", func() { It("should backup/restore in/from Rest backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -204,7 +200,7 @@ var _ = Describe("Rest Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/backend/s3.go b/test/e2e/backend/s3.go index 5999e774d..80d36b69b 100644 --- a/test/e2e/backend/s3.go +++ b/test/e2e/backend/s3.go @@ -17,8 +17,6 @@ limitations under the License. package backend import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("S3 Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -52,7 +47,7 @@ var _ = Describe("S3 Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from S3 backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -83,7 +78,7 @@ var _ = Describe("S3 Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -103,7 +98,7 @@ var _ = Describe("S3 Backend", func() { Context("WipeOut Repository", func() { It("should cleanup data from remote repository", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -146,7 +141,7 @@ var _ = Describe("S3 Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -177,7 +172,7 @@ var _ = Describe("S3 Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/backend/swift.go b/test/e2e/backend/swift.go index 3f1f7262f..133ed1236 100644 --- a/test/e2e/backend/swift.go +++ b/test/e2e/backend/swift.go @@ -17,8 +17,6 @@ limitations under the License. package backend import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("Swift Backend", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -52,7 +47,7 @@ var _ = Describe("Swift Backend", func() { Context("General Backup/Restore", func() { It("should backup/restore in/from Swift backend", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -83,7 +78,7 @@ var _ = Describe("Swift Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -103,7 +98,7 @@ var _ = Describe("Swift Backend", func() { Context("WipeOut Repository", func() { It("should cleanup data from remote repository", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -146,7 +141,7 @@ var _ = Describe("Swift Backend", func() { Context("Backup/Restore big file", func() { It("should backup/restore big file", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -177,7 +172,7 @@ var _ = Describe("Swift Backend", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/daemonset_test.go b/test/e2e/daemonset_test.go index 2a45adea1..6203530c7 100644 --- a/test/e2e/daemonset_test.go +++ b/test/e2e/daemonset_test.go @@ -79,7 +79,7 @@ var _ = XDescribe("DaemonSet", func() { } restic.Spec.Backend.StorageSecretName = cred.Name secondRestic.Spec.Backend.StorageSecretName = cred.Name - daemon = f.DaemonSet() + daemon = f.DaemonSet(fmt.Sprintf("%s-%s", framework.SourceDaemonSet, f.App()), framework.SourceVolume) localRef = api.LocalTypedReference{ Kind: apis.KindDaemonSet, Name: daemon.Name, diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index 0a5f4fada..260aa6e6e 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -88,7 +88,7 @@ var _ = XDescribe("Deployment", func() { pvc := f.PersistentVolumeClaim(rand.WithUniqSuffix("pvc")) _, err := f.CreatePersistentVolumeClaim(pvc) Expect(err).NotTo(HaveOccurred()) - deployment = f.Deployment(pvc.Name) + deployment = f.Deployment(pvc.Name, framework.SourceVolume) localRef = api.LocalTypedReference{ Kind: apis.KindDeployment, Name: deployment.Name, diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 9c3cfe5cf..c29512bf1 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -31,6 +31,7 @@ import ( _ "stash.appscode.dev/stash/test/e2e/backend" "stash.appscode.dev/stash/test/e2e/framework" _ "stash.appscode.dev/stash/test/e2e/hooks" + _ "stash.appscode.dev/stash/test/e2e/miscellaneous-use-cases" _ "stash.appscode.dev/stash/test/e2e/volumes" _ "stash.appscode.dev/stash/test/e2e/workloads" diff --git a/test/e2e/framework/backup_blueprint.go b/test/e2e/framework/backup_blueprint.go index 94329a09c..706c101ad 100644 --- a/test/e2e/framework/backup_blueprint.go +++ b/test/e2e/framework/backup_blueprint.go @@ -77,6 +77,9 @@ func (f *Framework) GetBackupBlueprint(name string) (*v1beta1.BackupBlueprint, e } func (f Invocation) CreateBackupBlueprintForWorkload(name string) (*v1beta1.BackupBlueprint, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + // Create Secret for BackupBlueprint secret, err := f.CreateBackendSecretForMinio() if err != nil { @@ -94,10 +97,13 @@ func (f Invocation) CreateBackupBlueprintForWorkload(name string) (*v1beta1.Back } func (f Invocation) CreateBackupBlueprintForPVC(name string) (*v1beta1.BackupBlueprint, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + // Create Secret for BackupBlueprint secret, err := f.CreateBackendSecretForMinio() if err != nil { - return &v1beta1.BackupBlueprint{}, err + return nil, err } // Generate BackupBlueprint definition @@ -107,6 +113,10 @@ func (f Invocation) CreateBackupBlueprintForPVC(name string) (*v1beta1.BackupBlu By(fmt.Sprintf("Creating BackupBlueprint: %s", bb.Name)) createdBB, err := f.CreateBackupBlueprint(bb) + if err != nil { + return nil, err + } f.AppendToCleanupList(createdBB) - return createdBB, err + + return createdBB, nil } diff --git a/test/e2e/framework/common.go b/test/e2e/framework/common.go index 2500db24e..b7aff70f5 100644 --- a/test/e2e/framework/common.go +++ b/test/e2e/framework/common.go @@ -79,7 +79,7 @@ func (f *Invocation) SetupWorkloadBackup(objMeta metav1.ObjectMeta, repo *api_v1 }, VolumeMounts: []core.VolumeMount{ { - Name: TestSourceDataVolumeName, + Name: SourceVolume, MountPath: TestSourceDataMountPath, }, }, @@ -150,7 +150,7 @@ func (f *Invocation) RestoredData(objMeta metav1.ObjectMeta, kind string) []stri return restoredData } -func (f *Invocation) SetupRestoreProcess(objMeta metav1.ObjectMeta, repo *api.Repository, kind string, transformFuncs ...func(restore *v1beta1.RestoreSession)) (*v1beta1.RestoreSession, error) { +func (f *Invocation) SetupRestoreProcess(objMeta metav1.ObjectMeta, repo *api.Repository, kind, volumeName string, transformFuncs ...func(restore *v1beta1.RestoreSession)) (*v1beta1.RestoreSession, error) { // Generate desired BackupConfiguration definition restoreSession := f.GetRestoreSession(repo.Name, func(restore *v1beta1.RestoreSession) { @@ -160,15 +160,18 @@ func (f *Invocation) SetupRestoreProcess(objMeta metav1.ObjectMeta, repo *api.Re }, } restore.Spec.Target = &v1beta1.RestoreTarget{ - Ref: GetTargetRef(objMeta.Name, kind), VolumeMounts: []core.VolumeMount{ { - Name: TestSourceDataVolumeName, + Name: volumeName, MountPath: TestSourceDataMountPath, }, }, } }) + // if objMeta is provided, then set target reference + if objMeta.Name != "" { + restoreSession.Spec.Target.Ref = GetTargetRef(objMeta.Name, kind) + } // transformFuncs provides a array of functions that made test specific change on the RestoreSession // apply these test specific changes. for _, fn := range transformFuncs { @@ -291,3 +294,10 @@ func (f *Invocation) VerifyAutoBackupConfigured(workloadMeta metav1.ObjectMeta, return backupConfig, err } + +func (f *Invocation) PrintDebugInfoOnFailure() { + if CurrentGinkgoTestDescription().Failed { + f.PrintDebugHelpers() + TestFailed = true + } +} diff --git a/test/e2e/framework/daemonset.go b/test/e2e/framework/daemonset.go index 4b6fd2aab..3f0d3ee0e 100644 --- a/test/e2e/framework/daemonset.go +++ b/test/e2e/framework/daemonset.go @@ -21,7 +21,6 @@ import ( "stash.appscode.dev/stash/pkg/util" - "github.com/appscode/go/crypto/rand" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" apps "k8s.io/api/apps/v1" @@ -34,14 +33,14 @@ import ( apps_util "kmodules.xyz/client-go/apps/v1" ) -func (fi *Invocation) DaemonSet() apps.DaemonSet { +func (fi *Invocation) DaemonSet(name, volumeName string) apps.DaemonSet { labels := map[string]string{ "app": fi.app, "kind": "daemonset", } daemon := apps.DaemonSet{ ObjectMeta: metav1.ObjectMeta{ - Name: rand.WithUniqSuffix("stash"), + Name: name, Namespace: fi.namespace, Labels: labels, }, @@ -65,7 +64,7 @@ func (fi *Invocation) DaemonSet() apps.DaemonSet { }, VolumeMounts: []core.VolumeMount{ { - Name: TestSourceDataVolumeName, + Name: volumeName, MountPath: TestSourceDataMountPath, }, }, @@ -73,7 +72,7 @@ func (fi *Invocation) DaemonSet() apps.DaemonSet { }, Volumes: []core.Volume{ { - Name: TestSourceDataVolumeName, + Name: volumeName, VolumeSource: core.VolumeSource{ HostPath: &core.HostPathVolumeSource{ Path: TestSourceDataMountPath, @@ -167,10 +166,12 @@ func (f *Invocation) WaitUntilDaemonSetReadyWithInitContainer(meta metav1.Object }) } -func (f *Invocation) DeployDaemonSet(name string) (*apps.DaemonSet, error) { +func (f *Invocation) DeployDaemonSet(name string, volumeName string) (*apps.DaemonSet, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + // Generate DaemonSet definition - dmn := f.DaemonSet() - dmn.Name = name + dmn := f.DaemonSet(name, volumeName) By(fmt.Sprintf("Deploying DaemonSet: %s/%s", dmn.Namespace, dmn.Name)) createdDmn, err := f.CreateDaemonSet(dmn) diff --git a/test/e2e/framework/deployment.go b/test/e2e/framework/deployment.go index 3c8db7bab..9a1e9195c 100644 --- a/test/e2e/framework/deployment.go +++ b/test/e2e/framework/deployment.go @@ -17,6 +17,7 @@ limitations under the License. package framework import ( + "fmt" "time" "stash.appscode.dev/stash/pkg/util" @@ -43,7 +44,7 @@ const ( TcpPort = 9090 ) -func (fi *Invocation) Deployment(pvcName string) apps.Deployment { +func (fi *Invocation) Deployment(pvcName, volName string) apps.Deployment { labels := map[string]string{ "app": fi.app, "kind": "deployment", @@ -59,7 +60,7 @@ func (fi *Invocation) Deployment(pvcName string) apps.Deployment { Selector: &metav1.LabelSelector{ MatchLabels: labels, }, - Template: fi.PodTemplate(labels, pvcName), + Template: fi.PodTemplate(labels, pvcName, volName), }, } } @@ -143,18 +144,30 @@ func (f *Invocation) WaitUntilDeploymentReadyWithInitContainer(meta metav1.Objec }) } -func (f *Invocation) DeployDeployment(name string, replica int32, transformFuncs ...func(dp *apps.Deployment)) (*apps.Deployment, error) { - // Create PVC for Deployment - pvc, err := f.CreateNewPVC(name) +func (f *Invocation) DeployDeployment(name string, replica int32, volName string, transformFuncs ...func(dp *apps.Deployment)) (*apps.Deployment, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + pvcName := fmt.Sprintf("%s-%s", volName, f.app) + + // If the PVC does not exist, create PVC for Deployment + pvc, err := f.KubeClient.CoreV1().PersistentVolumeClaims(f.namespace).Get(pvcName, metav1.GetOptions{}) if err != nil { - return &apps.Deployment{}, err + if kerr.IsNotFound(err) { + pvc, err = f.CreateNewPVC(pvcName) + if err != nil { + return nil, err + } + } else { + return nil, err + } } + // Generate Deployment definition - deployment := f.Deployment(pvc.Name) + deployment := f.Deployment(pvc.Name, volName) deployment.Name = name deployment.Spec.Replicas = &replica - // transformFuncs provides a array of functions that made test specific change on the BackupConfiguration + // transformFuncs provides a array of functions that made test specific change on the Deployment // apply these test specific changes for _, fn := range transformFuncs { fn(&deployment) diff --git a/test/e2e/framework/pod.go b/test/e2e/framework/pod.go index 474bc7885..e46c814a7 100644 --- a/test/e2e/framework/pod.go +++ b/test/e2e/framework/pod.go @@ -40,7 +40,7 @@ const ( OperatorName = "stash-operator" ) -func (fi *Invocation) PodTemplate(labels map[string]string, pvcName string) core.PodTemplateSpec { +func (fi *Invocation) PodTemplate(labels map[string]string, pvcName, volName string) core.PodTemplateSpec { return core.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, @@ -57,7 +57,7 @@ func (fi *Invocation) PodTemplate(labels map[string]string, pvcName string) core }, VolumeMounts: []core.VolumeMount{ { - Name: TestSourceDataVolumeName, + Name: volName, MountPath: TestSourceDataMountPath, }, }, @@ -65,7 +65,7 @@ func (fi *Invocation) PodTemplate(labels map[string]string, pvcName string) core }, Volumes: []core.Volume{ { - Name: TestSourceDataVolumeName, + Name: volName, VolumeSource: core.VolumeSource{ PersistentVolumeClaim: &core.PersistentVolumeClaimVolumeSource{ ClaimName: pvcName, diff --git a/test/e2e/framework/pvc.go b/test/e2e/framework/pvc.go index 54763c2f8..ee1ccb25f 100644 --- a/test/e2e/framework/pvc.go +++ b/test/e2e/framework/pvc.go @@ -23,7 +23,6 @@ import ( "stash.appscode.dev/stash/apis/stash/v1alpha1" "stash.appscode.dev/stash/apis/stash/v1beta1" - "github.com/appscode/go/crypto/rand" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" core "k8s.io/api/core/v1" @@ -35,7 +34,7 @@ import ( func (f *Invocation) PersistentVolumeClaim(name string) *core.PersistentVolumeClaim { return &core.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ - Name: rand.WithUniqSuffix("pvc"), + Name: name, Namespace: f.namespace, }, Spec: core.PersistentVolumeClaimSpec{ @@ -70,9 +69,12 @@ func (f *Invocation) CreateNewPVC(name string) (*core.PersistentVolumeClaim, err By(fmt.Sprintf("Creating PVC: %s/%s", pvc.Namespace, pvc.Name)) createdPVC, err := f.CreatePersistentVolumeClaim(pvc) + if err != nil { + return nil, err + } f.AppendToCleanupList(createdPVC) - return createdPVC, err + return createdPVC, nil } func (f *Invocation) SetupPVCBackup(pvc *core.PersistentVolumeClaim, repo *v1alpha1.Repository, transformFuncs ...func(bc *v1beta1.BackupConfiguration)) (*v1beta1.BackupConfiguration, error) { diff --git a/test/e2e/framework/replicaset.go b/test/e2e/framework/replicaset.go index fedce563b..9e1546fec 100644 --- a/test/e2e/framework/replicaset.go +++ b/test/e2e/framework/replicaset.go @@ -17,6 +17,8 @@ limitations under the License. package framework import ( + "fmt" + "stash.appscode.dev/stash/pkg/util" "github.com/appscode/go/crypto/rand" @@ -31,7 +33,7 @@ import ( apps_util "kmodules.xyz/client-go/apps/v1" ) -func (fi *Invocation) ReplicaSet(pvcName string) apps.ReplicaSet { +func (fi *Invocation) ReplicaSet(pvcName, volName string) apps.ReplicaSet { labels := map[string]string{ "app": fi.app, "kind": "replicaset", @@ -47,7 +49,7 @@ func (fi *Invocation) ReplicaSet(pvcName string) apps.ReplicaSet { MatchLabels: labels, }, Replicas: types.Int32P(1), - Template: fi.PodTemplate(labels, pvcName), + Template: fi.PodTemplate(labels, pvcName, volName), }, } } @@ -128,14 +130,26 @@ func (f *Invocation) WaitUntilRSReadyWithInitContainer(meta metav1.ObjectMeta) e }) } -func (f *Invocation) DeployReplicaSet(name string, replica int32) (*apps.ReplicaSet, error) { - // Create PVC for ReplicaSet - pvc, err := f.CreateNewPVC(name) +func (f *Invocation) DeployReplicaSet(name string, replica int32, volName string) (*apps.ReplicaSet, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + pvcName := fmt.Sprintf("%s-%s", volName, f.app) + + // If the PVC does not exist, create PVC for ReplicaSet + pvc, err := f.KubeClient.CoreV1().PersistentVolumeClaims(f.namespace).Get(pvcName, metav1.GetOptions{}) if err != nil { - return &apps.ReplicaSet{}, err + if kerr.IsNotFound(err) { + pvc, err = f.CreateNewPVC(pvcName) + if err != nil { + return nil, err + } + } else { + return nil, err + } } + // Generate ReplicaSet definition - rs := f.ReplicaSet(pvc.Name) + rs := f.ReplicaSet(pvc.Name, volName) rs.Spec.Replicas = &replica rs.Name = name diff --git a/test/e2e/framework/replicationcontroller.go b/test/e2e/framework/replicationcontroller.go index 2110fa3e4..9a8d65fb2 100644 --- a/test/e2e/framework/replicationcontroller.go +++ b/test/e2e/framework/replicationcontroller.go @@ -17,6 +17,8 @@ limitations under the License. package framework import ( + "fmt" + "stash.appscode.dev/stash/pkg/util" "github.com/appscode/go/crypto/rand" @@ -30,12 +32,12 @@ import ( kutil "kmodules.xyz/client-go" ) -func (fi *Invocation) ReplicationController(pvcName string) core.ReplicationController { +func (fi *Invocation) ReplicationController(pvcName, volName string) core.ReplicationController { labels := map[string]string{ "app": fi.app, "kind": "replicationcontroller", } - podTemplate := fi.PodTemplate(labels, pvcName) + podTemplate := fi.PodTemplate(labels, pvcName, volName) return core.ReplicationController{ ObjectMeta: metav1.ObjectMeta{ Name: rand.WithUniqSuffix("stash"), @@ -127,14 +129,26 @@ func (f *Invocation) WaitUntilRCReadyWithInitContainer(meta metav1.ObjectMeta) e }) } -func (f *Invocation) DeployReplicationController(name string, replica int32) (*core.ReplicationController, error) { - // Create PVC for ReplicationController - pvc, err := f.CreateNewPVC(name) +func (f *Invocation) DeployReplicationController(name string, replica int32, volName string) (*core.ReplicationController, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + pvcName := fmt.Sprintf("%s-%s", volName, f.app) + + // If the PVC does not exist, create PVC for Deployment + pvc, err := f.KubeClient.CoreV1().PersistentVolumeClaims(f.namespace).Get(pvcName, metav1.GetOptions{}) if err != nil { - return &core.ReplicationController{}, err + if kerr.IsNotFound(err) { + pvc, err = f.CreateNewPVC(pvcName) + if err != nil { + return nil, err + } + } else { + return nil, err + } } + // Generate ReplicationController definition - rc := f.ReplicationController(pvc.Name) + rc := f.ReplicationController(pvc.Name, volName) rc.Spec.Replicas = &replica rc.Name = name diff --git a/test/e2e/framework/statefulset.go b/test/e2e/framework/statefulset.go index b152353e1..81e25b94c 100644 --- a/test/e2e/framework/statefulset.go +++ b/test/e2e/framework/statefulset.go @@ -17,6 +17,8 @@ limitations under the License. package framework import ( + "fmt" + "stash.appscode.dev/stash/pkg/util" "github.com/appscode/go/crypto/rand" @@ -33,7 +35,7 @@ import ( apps_util "kmodules.xyz/client-go/apps/v1" ) -func (fi *Invocation) StatefulSet(pvcName string) apps.StatefulSet { +func (fi *Invocation) StatefulSet(pvcName, volName string) apps.StatefulSet { labels := map[string]string{ "app": fi.app, "kind": "statefulset", @@ -49,7 +51,7 @@ func (fi *Invocation) StatefulSet(pvcName string) apps.StatefulSet { MatchLabels: labels, }, Replicas: types.Int32P(1), - Template: fi.PodTemplate(labels, pvcName), + Template: fi.PodTemplate(labels, pvcName, volName), ServiceName: TEST_HEADLESS_SERVICE, UpdateStrategy: apps.StatefulSetUpdateStrategy{ Type: apps.RollingUpdateStatefulSetStrategyType, @@ -58,14 +60,14 @@ func (fi *Invocation) StatefulSet(pvcName string) apps.StatefulSet { } } -func (fi *Invocation) StatefulSetForV1beta1API() apps.StatefulSet { +func (fi *Invocation) StatefulSetForV1beta1API(name, volName string, replica int32) apps.StatefulSet { labels := map[string]string{ "app": fi.app, "kind": "statefulset", } return apps.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ - Name: rand.WithUniqSuffix("stash"), + Name: name, Namespace: fi.namespace, Labels: labels, }, @@ -73,7 +75,7 @@ func (fi *Invocation) StatefulSetForV1beta1API() apps.StatefulSet { Selector: &metav1.LabelSelector{ MatchLabels: labels, }, - Replicas: types.Int32P(3), + Replicas: &replica, ServiceName: TEST_HEADLESS_SERVICE, Template: core.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -91,7 +93,7 @@ func (fi *Invocation) StatefulSetForV1beta1API() apps.StatefulSet { }, VolumeMounts: []core.VolumeMount{ { - Name: TestSourceDataVolumeName, + Name: volName, MountPath: TestSourceDataMountPath, }, }, @@ -102,7 +104,7 @@ func (fi *Invocation) StatefulSetForV1beta1API() apps.StatefulSet { VolumeClaimTemplates: []core.PersistentVolumeClaim{ { ObjectMeta: metav1.ObjectMeta{ - Name: TestSourceDataVolumeName, + Name: volName, }, Spec: core.PersistentVolumeClaimSpec{ AccessModes: []core.PersistentVolumeAccessMode{ @@ -111,7 +113,7 @@ func (fi *Invocation) StatefulSetForV1beta1API() apps.StatefulSet { StorageClassName: types.StringP(fi.StorageClass), Resources: core.ResourceRequirements{ Requests: core.ResourceList{ - core.ResourceName(core.ResourceStorage): resource.MustParse("1Gi"), + core.ResourceStorage: resource.MustParse("1Gi"), }, }, }, @@ -197,11 +199,18 @@ func (f *Invocation) WaitUntilStatefulSetWithInitContainer(meta metav1.ObjectMet }) } -func (f *Invocation) DeployStatefulSet(name string, replica int32) (*apps.StatefulSet, error) { +func (f *Invocation) DeployStatefulSet(name string, replica int32, volName string, transformFuncs ...func(ss *apps.StatefulSet)) (*apps.StatefulSet, error) { + // append test case specific suffix so that name does not conflict during parallel test + name = fmt.Sprintf("%s-%s", name, f.app) + // Generate StatefulSet definition - ss := f.StatefulSetForV1beta1API() - ss.Spec.Replicas = &replica - ss.Name = name + ss := f.StatefulSetForV1beta1API(name, volName, replica) + + // transformFuncs provides a array of functions that made test specific change on the StatefulSet + // apply these test specific changes + for _, fn := range transformFuncs { + fn(&ss) + } By("Deploying StatefulSet: " + ss.Name) createdss, err := f.CreateStatefulSet(ss) @@ -220,7 +229,7 @@ func (f *Invocation) DeployStatefulSet(name string, replica int32) (*apps.Statef return createdss, err } -func (f *Invocation) DeployStatefulSetWithProbeClient(name string) (*apps.StatefulSet, error) { +func (f *Invocation) DeployStatefulSetWithProbeClient() (*apps.StatefulSet, error) { svc, err := f.CreateService(f.HeadlessService()) if err != nil { return nil, err @@ -234,7 +243,7 @@ func (f *Invocation) DeployStatefulSetWithProbeClient(name string) (*apps.Statef // Generate StatefulSet definition statefulset := &apps.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ - Name: name, + Name: fmt.Sprintf("%s-%s", ProberDemoPodPrefix, f.app), Namespace: f.namespace, }, Spec: apps.StatefulSetSpec{ @@ -277,7 +286,7 @@ func (f *Invocation) DeployStatefulSetWithProbeClient(name string) (*apps.Statef }, VolumeMounts: []core.VolumeMount{ { - Name: TestSourceDataVolumeName, + Name: SourceVolume, MountPath: TestSourceDataMountPath, }, }, @@ -288,7 +297,7 @@ func (f *Invocation) DeployStatefulSetWithProbeClient(name string) (*apps.Statef VolumeClaimTemplates: []core.PersistentVolumeClaim{ { ObjectMeta: metav1.ObjectMeta{ - Name: TestSourceDataVolumeName, + Name: SourceVolume, }, Spec: core.PersistentVolumeClaimSpec{ AccessModes: []core.PersistentVolumeAccessMode{ @@ -297,7 +306,7 @@ func (f *Invocation) DeployStatefulSetWithProbeClient(name string) (*apps.Statef StorageClassName: types.StringP(f.StorageClass), Resources: core.ResourceRequirements{ Requests: core.ResourceList{ - core.ResourceName(core.ResourceStorage): resource.MustParse("1Gi"), + core.ResourceStorage: resource.MustParse("1Gi"), }, }, }, diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 95bbe4d0b..c374b8b6b 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -56,20 +56,41 @@ var ( ) const ( - TestSoucreDemoDataPath = "/data/stash-test/demo-data" - TestSourceDataDir1 = "/source/data/dir-1" - TestSourceDataDir2 = "/source/data/dir-2" - KindRestic = "Restic" - KindRepository = "Repository" - KindRecovery = "Recovery" - PullInterval = time.Second * 2 - WaitTimeOut = time.Minute * 3 - TaskPVCBackup = "pvc-backup" - TaskPVCRestore = "pvc-restore" - TestSourceDataTargetPath = "/source/data" - TestSourceDataVolumeMount = "source-data:/source/data" - WrongBackupBlueprintName = "backup-blueprint" - WrongTargetPath = "/source/data-1" + TestSoucreDemoDataPath = "/data/stash-test/demo-data" + TestSourceDataDir1 = "/source/data/dir-1" + TestSourceDataDir2 = "/source/data/dir-2" + KindRestic = "Restic" + KindRepository = "Repository" + KindRecovery = "Recovery" + PullInterval = time.Second * 2 + WaitTimeOut = time.Minute * 3 + TaskPVCBackup = "pvc-backup" + TaskPVCRestore = "pvc-restore" + TestSourceDataTargetPath = "/source/data" + TestSourceVolumeAndMount = SourceVolume + ":" + TestSourceDataMountPath + WrongBackupBlueprintName = "backup-blueprint" + WrongTargetPath = "/source/data-1" + + SourceDeployment = "source-dp" + RestoredDeployment = "restored-dp" + + SourceStatefulSet = "source-ss" + RestoredStatefulSet = "restored-ss" + + SourceDaemonSet = "source-dmn" + RestoredDaemonSet = "restored-dmn" + + SourceReplicaSet = "source-rs" + RestoredReplicaSet = "restored-rs" + + SourceReplicationController = "source-rc" + RestoredReplicationController = "restored-rc" + + SourceVolume = "source-volume" + RestoredVolume = "restored-volume" + + WorkloadBackupBlueprint = "workload-backup-blueprint" + PvcBackupBlueprint = "pvc-backup-blueprint" ) func (f *Framework) EventualEvent(meta metav1.ObjectMeta) GomegaAsyncAssertion { diff --git a/test/e2e/hooks/post_backup.go b/test/e2e/hooks/post_backup.go index da370074e..459769155 100644 --- a/test/e2e/hooks/post_backup.go +++ b/test/e2e/hooks/post_backup.go @@ -43,10 +43,7 @@ var _ = Describe("PostBackup Hook", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -61,7 +58,7 @@ var _ = Describe("PostBackup Hook", func() { It("should execute hook successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -102,7 +99,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Host and Port from Pod", func() { It("should execute hook successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -144,7 +141,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Failure Test", func() { It("should take a backup even when the postBackup hook failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -196,7 +193,7 @@ var _ = Describe("PostBackup Hook", func() { It("should execute hook successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -237,7 +234,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Host and Port from Pod", func() { It("should execute hook successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -278,7 +275,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Json Data in Request Body", func() { It("server should echo the 'expectedCode' and 'expectedResponse' passed in the json body", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -320,7 +317,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Form Data in Request Body", func() { It("server should echo the 'expectedCode' and 'expectedResponse' passed as form data", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -372,7 +369,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Failure Test", func() { It("should take a backup even when the postBackup hook failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -434,7 +431,7 @@ var _ = Describe("PostBackup Hook", func() { It("should execute hook successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -473,7 +470,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Host and Port from Pod", func() { It("should execute hook successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -513,7 +510,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Failure Test", func() { It("should take a backup even when the postBackup hook failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -561,7 +558,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Success Test", func() { It("should cleanup the sample data in postBackup hook", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -608,7 +605,7 @@ var _ = Describe("PostBackup Hook", func() { It("should execute postBackup hook even when the backup process failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -660,7 +657,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Failure Test", func() { It("should take a backup even when the postBackup hook failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -713,7 +710,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Success Cases", func() { It("should cleanup the sample data in postBackup hook", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -765,7 +762,7 @@ var _ = Describe("PostBackup Hook", func() { It("should execute postBackup hook even when the backup process failed", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -821,7 +818,7 @@ var _ = Describe("PostBackup Hook", func() { Context("Failure Cases", func() { It("should take backup even when the postBackup hook failed", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod diff --git a/test/e2e/hooks/post_restore.go b/test/e2e/hooks/post_restore.go index da9db0b6f..6fdd309ed 100644 --- a/test/e2e/hooks/post_restore.go +++ b/test/e2e/hooks/post_restore.go @@ -46,10 +46,7 @@ var _ = Describe("PostRestore Hook", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -63,7 +60,7 @@ var _ = Describe("PostRestore Hook", func() { It("should execute the postRestore hook successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -106,7 +103,7 @@ var _ = Describe("PostRestore Hook", func() { // Restore the backed up data // Remove the corrupted data in postRestore hook. By("Restoring the backed up data in the original StatefulSet") - restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, func(restore *v1beta1.RestoreSession) { + restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, framework.SourceVolume, func(restore *v1beta1.RestoreSession) { restore.Spec.Hooks = &v1beta1.RestoreHooks{ PostRestore: &probev1.Handler{ Exec: &core.ExecAction{ @@ -131,7 +128,7 @@ var _ = Describe("PostRestore Hook", func() { It("should execute the postRestore hook even when the restore process failed", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -175,7 +172,7 @@ var _ = Describe("PostRestore Hook", func() { // Try to restore a directory that hasn't been backed up. This will force the restore process to fail. // Remove the corrupted data in postRestore hook. By("Restoring the backed up data in the original StatefulSet") - restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, func(restore *v1beta1.RestoreSession) { + restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, framework.SourceVolume, func(restore *v1beta1.RestoreSession) { restore.Spec.Hooks = &v1beta1.RestoreHooks{ PostRestore: &probev1.Handler{ Exec: &core.ExecAction{ @@ -217,7 +214,7 @@ var _ = Describe("PostRestore Hook", func() { It("should restore backed up data even when the hook failed", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -257,7 +254,7 @@ var _ = Describe("PostRestore Hook", func() { // Restore the backed up data // Return non-zero exit code from postRestore hook so that it fail By("Restoring the backed up data in the original StatefulSet") - restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, func(restore *v1beta1.RestoreSession) { + restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, framework.SourceVolume, func(restore *v1beta1.RestoreSession) { restore.Spec.Hooks = &v1beta1.RestoreHooks{ PostRestore: &probev1.Handler{ Exec: &core.ExecAction{ @@ -296,7 +293,7 @@ var _ = Describe("PostRestore Hook", func() { Context("Success Cases", func() { It("should execute postRestore hook successfully", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -365,7 +362,7 @@ var _ = Describe("PostRestore Hook", func() { It("should execute postRestore hook even when the restore process failed", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -442,7 +439,7 @@ var _ = Describe("PostRestore Hook", func() { Context("Failure Cases", func() { It("should restore the backed up data even when the hook failed", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod diff --git a/test/e2e/hooks/pre_backup.go b/test/e2e/hooks/pre_backup.go index 782e6659e..bfd386c2c 100644 --- a/test/e2e/hooks/pre_backup.go +++ b/test/e2e/hooks/pre_backup.go @@ -45,10 +45,7 @@ var _ = Describe("PreBackup Hook", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -63,7 +60,7 @@ var _ = Describe("PreBackup Hook", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -104,7 +101,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Host and Port from Pod", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -146,7 +143,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Failure Test", func() { It("should not take backup when probe failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -204,7 +201,7 @@ var _ = Describe("PreBackup Hook", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -245,7 +242,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Host and Port from Pod", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -286,7 +283,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Json Data in Request Body", func() { It("server should echo the 'expectedCode' and 'expectedResponse' passed in the json body", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -328,7 +325,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Form Data in Request Body", func() { It("server should echo the 'expectedCode' and 'expectedResponse' passed as form data", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -380,7 +377,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Failure Test", func() { It("should not take backup when probe failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -448,7 +445,7 @@ var _ = Describe("PreBackup Hook", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -487,7 +484,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Host and Port from Pod", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -527,7 +524,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Failure Test", func() { It("should not take backup when probe failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -581,7 +578,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Success Test", func() { It("should execute probe successfully", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -620,7 +617,7 @@ var _ = Describe("PreBackup Hook", func() { Context("Failure Test", func() { It("should not take backup when probe failed", func() { // Deploy a StatefulSet. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Generate Sample Data diff --git a/test/e2e/hooks/pre_restore.go b/test/e2e/hooks/pre_restore.go index 823c81f81..94722f217 100644 --- a/test/e2e/hooks/pre_restore.go +++ b/test/e2e/hooks/pre_restore.go @@ -46,10 +46,7 @@ var _ = Describe("PreRestore Hook", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -63,7 +60,7 @@ var _ = Describe("PreRestore Hook", func() { It("should remove the corrupted data in preRestore hook", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -105,7 +102,7 @@ var _ = Describe("PreRestore Hook", func() { // Restore the backed up data // Remove corrupted data in preRestore hook By("Restoring the backed up data in the original StatefulSet") - restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, func(restore *v1beta1.RestoreSession) { + restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, framework.SourceVolume, func(restore *v1beta1.RestoreSession) { restore.Spec.Hooks = &v1beta1.RestoreHooks{ PreRestore: &probev1.Handler{ Exec: &core.ExecAction{ @@ -132,7 +129,7 @@ var _ = Describe("PreRestore Hook", func() { It("should not restore when preRestore hook failed", func() { // Deploy a StatefulSet with prober client. Here, we are using a StatefulSet because we need a stable address // for pod where http request will be sent. - statefulset, err := f.DeployStatefulSetWithProbeClient(fmt.Sprintf("%s-%s", framework.ProberDemoPodPrefix, f.App())) + statefulset, err := f.DeployStatefulSetWithProbeClient() Expect(err).NotTo(HaveOccurred()) // Read data at empty state @@ -172,7 +169,7 @@ var _ = Describe("PreRestore Hook", func() { // Restore the backed up data // Return a non-zero exit code from preRestore hook so that the hook fail By("Restoring the backed up data") - restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, func(restore *v1beta1.RestoreSession) { + restoreSession, err := f.SetupRestoreProcess(statefulset.ObjectMeta, repo, apis.KindStatefulSet, framework.SourceVolume, func(restore *v1beta1.RestoreSession) { restore.Spec.Hooks = &v1beta1.RestoreHooks{ PreRestore: &probev1.Handler{ Exec: &core.ExecAction{ diff --git a/test/e2e/miscellaneous-use-cases/clone_pvc.go b/test/e2e/miscellaneous-use-cases/clone_pvc.go new file mode 100644 index 000000000..cf0d921d5 --- /dev/null +++ b/test/e2e/miscellaneous-use-cases/clone_pvc.go @@ -0,0 +1,207 @@ +/* +Copyright The Stash Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package miscellaneous_use_cases + +import ( + "fmt" + "time" + + "stash.appscode.dev/stash/apis" + "stash.appscode.dev/stash/apis/stash/v1beta1" + "stash.appscode.dev/stash/test/e2e/framework" + . "stash.appscode.dev/stash/test/e2e/matcher" + + "github.com/appscode/go/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + ofst "kmodules.xyz/offshoot-api/api/v1" +) + +var _ = Describe("Clone", func() { + + var f *framework.Invocation + + BeforeEach(func() { + f = framework.NewInvocation() + }) + + JustAfterEach(func() { + f.PrintDebugInfoOnFailure() + }) + + AfterEach(func() { + err := f.CleanupTestResources() + Expect(err).NotTo(HaveOccurred()) + }) + + Context("Deployment's Volumes", func() { + Context("Restore using VolumeClaimTemplate", func() { + It("should create PVC according to the VolumeClaimTemplate and restore there", func() { + // Deploy a Deployment + deploy, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) + Expect(err).NotTo(HaveOccurred()) + + // Generate Sample Data + sampleData, err := f.GenerateSampleData(deploy.ObjectMeta, apis.KindDeployment) + Expect(err).NotTo(HaveOccurred()) + + // Setup a Minio Repository + repo, err := f.SetupMinioRepository() + Expect(err).NotTo(HaveOccurred()) + f.AppendToCleanupList(repo) + + // Setup workload Backup + backupConfig, err := f.SetupWorkloadBackup(deploy.ObjectMeta, repo, apis.KindDeployment) + Expect(err).NotTo(HaveOccurred()) + + // Take an Instant Backup the Sample Data + backupSession, err := f.TakeInstantBackup(backupConfig.ObjectMeta) + Expect(err).NotTo(HaveOccurred()) + + By("Verifying that BackupSession has succeeded") + completedBS, err := f.StashClient.StashV1beta1().BackupSessions(backupSession.Namespace).Get(backupSession.Name, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) + + // Restore PVC according to VolumeClaimTemplate + By("Restoring the backed up data using VolumeClaimTemplate") + restoredPVCName := fmt.Sprintf("%s-%s", framework.RestoredVolume, f.App()) + restoreSession, err := f.SetupRestoreProcess(metav1.ObjectMeta{}, repo, apis.KindPersistentVolumeClaim, restoredPVCName, func(restore *v1beta1.RestoreSession) { + restore.Spec.Target.VolumeClaimTemplates = []ofst.PersistentVolumeClaim{ + { + PartialObjectMeta: ofst.PartialObjectMeta{ + Name: restoredPVCName, + Namespace: f.Namespace(), + CreationTimestamp: metav1.Time{ + Time: time.Now(), + }, + }, + Spec: core.PersistentVolumeClaimSpec{ + AccessModes: []core.PersistentVolumeAccessMode{ + core.ReadWriteOnce, + }, + StorageClassName: types.StringP(f.StorageClass), + Resources: core.ResourceRequirements{ + Requests: core.ResourceList{ + core.ResourceStorage: resource.MustParse("10Mi"), + }, + }, + }, + }, + } + }) + Expect(err).NotTo(HaveOccurred()) + + By("Verifying that RestoreSession succeeded") + completedRS, err := f.StashClient.StashV1beta1().RestoreSessions(restoreSession.Namespace).Get(restoreSession.Name, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + Expect(completedRS.Status.Phase).Should(Equal(v1beta1.RestoreSessionSucceeded)) + + // Deploy restored Deployment + restoredDeploy, err := f.DeployDeployment(framework.RestoredDeployment, int32(1), framework.RestoredVolume) + Expect(err).NotTo(HaveOccurred()) + + // Get restored data + restoredData := f.RestoredData(restoredDeploy.ObjectMeta, apis.KindDeployment) + + // Verify that restored data is same as the original data + By("Verifying restored data is same as the original data") + Expect(restoredData).Should(BeSameAs(sampleData)) + }) + }) + }) + + Context("StatefulSet's Volumes", func() { + Context("Restore using VolumeClaimTemplate", func() { + It("should create PVC according to the VolumeClaimTemplate and restore there", func() { + // Deploy a StatefulSet + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, 3, framework.SourceVolume) + Expect(err).NotTo(HaveOccurred()) + + // Generate Sample Data + sampleData, err := f.GenerateSampleData(ss.ObjectMeta, apis.KindStatefulSet) + Expect(err).NotTo(HaveOccurred()) + + // Setup a Minio Repository + repo, err := f.SetupMinioRepository() + Expect(err).NotTo(HaveOccurred()) + f.AppendToCleanupList(repo) + + // Setup workload Backup + backupConfig, err := f.SetupWorkloadBackup(ss.ObjectMeta, repo, apis.KindStatefulSet) + Expect(err).NotTo(HaveOccurred()) + + // Take an Instant Backup the Sample Data + backupSession, err := f.TakeInstantBackup(backupConfig.ObjectMeta) + Expect(err).NotTo(HaveOccurred()) + + By("Verifying that BackupSession has succeeded") + completedBS, err := f.StashClient.StashV1beta1().BackupSessions(backupSession.Namespace).Get(backupSession.Name, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) + + // Restore PVC according to VolumeClaimTemplate + By("Restoring the backed up data into PVC") + restoredPVCNamePrefix := fmt.Sprintf("%s-%s-%s", framework.RestoredVolume, framework.RestoredStatefulSet, f.App()) + restoreSession, err := f.SetupRestoreProcess(metav1.ObjectMeta{}, repo, apis.KindPersistentVolumeClaim, restoredPVCNamePrefix, func(restore *v1beta1.RestoreSession) { + restore.Spec.Target.Replicas = types.Int32P(3) + restore.Spec.Target.VolumeClaimTemplates = []ofst.PersistentVolumeClaim{ + { + PartialObjectMeta: ofst.PartialObjectMeta{ + Name: fmt.Sprintf("%s-${POD_ORDINAL}", restoredPVCNamePrefix), + Namespace: f.Namespace(), + CreationTimestamp: metav1.Time{ + Time: time.Now(), + }, + }, + Spec: core.PersistentVolumeClaimSpec{ + AccessModes: []core.PersistentVolumeAccessMode{ + core.ReadWriteOnce, + }, + StorageClassName: types.StringP(f.StorageClass), + Resources: core.ResourceRequirements{ + Requests: core.ResourceList{ + core.ResourceStorage: resource.MustParse("10Mi"), + }, + }, + }, + }, + } + }) + Expect(err).NotTo(HaveOccurred()) + + By("Verifying that RestoreSession succeeded") + completedRS, err := f.StashClient.StashV1beta1().RestoreSessions(restoreSession.Namespace).Get(restoreSession.Name, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + Expect(completedRS.Status.Phase).Should(Equal(v1beta1.RestoreSessionSucceeded)) + + //Deploy restored StatefulSet + restoredSS, err := f.DeployStatefulSet(framework.RestoredStatefulSet, int32(3), framework.RestoredVolume) + Expect(err).NotTo(HaveOccurred()) + + // Get restored data + restoredData := f.RestoredData(restoredSS.ObjectMeta, apis.KindStatefulSet) + + // Verify that restored data is same as the original data + By("Verifying restored data is same as the original data") + Expect(restoredData).Should(BeSameAs(sampleData)) + }) + }) + }) +}) diff --git a/test/e2e/miscellaneous-use-cases/repository.go b/test/e2e/miscellaneous-use-cases/repository.go new file mode 100644 index 000000000..f83f55bc3 --- /dev/null +++ b/test/e2e/miscellaneous-use-cases/repository.go @@ -0,0 +1,159 @@ +/* +Copyright The Stash Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package miscellaneous_use_cases + +import ( + "fmt" + + "stash.appscode.dev/stash/apis" + "stash.appscode.dev/stash/apis/stash/v1beta1" + "stash.appscode.dev/stash/pkg/eventer" + "stash.appscode.dev/stash/test/e2e/framework" + "stash.appscode.dev/stash/test/e2e/matcher" + + "github.com/appscode/go/crypto/rand" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + core "k8s.io/api/core/v1" + store "kmodules.xyz/objectstore-api/api/v1" +) + +var _ = Describe("Repository", func() { + + var f *framework.Invocation + + BeforeEach(func() { + f = framework.NewInvocation() + }) + + JustAfterEach(func() { + f.PrintDebugInfoOnFailure() + }) + + AfterEach(func() { + err := f.CleanupTestResources() + Expect(err).NotTo(HaveOccurred()) + }) + + Context("Local Backend", func() { + Context("Invalid MountPath", func() { + It("should reject to create Repository for using `/stash` as `mountPath`", func() { + // Deploy a Deployment + _, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) + Expect(err).NotTo(HaveOccurred()) + + // Create Storage Secret + By("Creating Storage Secret") + cred := f.SecretForLocalBackend() + _, err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + f.AppendToCleanupList(&cred) + + // We are going to use an PVC as backend + pvc, err := f.CreateNewPVC(rand.WithUniqSuffix("backend-pvc")) + Expect(err).NotTo(HaveOccurred()) + + // Generate Repository Definition + repo := f.NewLocalRepositoryWithPVC(cred.Name, pvc.Name) + + // Use `/stash` as `mountPath` + repo.Spec.Backend.Local.MountPath = "/stash" + + // reject to create Repository + By("reject to create Repository") + _, err = f.StashClient.StashV1alpha1().Repositories(repo.Namespace).Create(repo) + Expect(err).To(HaveOccurred()) + }) + + It("should reject to create Repository for using `/stash/data` as `mountPath`", func() { + // Deploy a Deployment + _, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) + Expect(err).NotTo(HaveOccurred()) + + // Create Storage Secret + By("Creating Storage Secret") + cred := f.SecretForLocalBackend() + _, err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + f.AppendToCleanupList(&cred) + + // We are going to use an PVC as backend + pvc, err := f.CreateNewPVC(rand.WithUniqSuffix("backend-pvc")) + Expect(err).NotTo(HaveOccurred()) + + // Generate Repository Definition + repo := f.NewLocalRepositoryWithPVC(cred.Name, pvc.Name) + + // Use `/stash` as `mountPath` + repo.Spec.Backend.Local.MountPath = "/stash/data" + + // reject to create Repository + By("reject to create Repository") + _, err = f.StashClient.StashV1alpha1().Repositories(repo.Namespace).Create(repo) + Expect(err).To(HaveOccurred()) + }) + }) + + Context("Invalid MountPath in Auto-Backup", func() { + annotations := func(backupBlueprintName string) map[string]string { + return map[string]string{ + v1beta1.KeyBackupBlueprint: backupBlueprintName, + v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, + v1beta1.KeyVolumeMounts: framework.TestSourceVolumeAndMount, + } + } + + It("should reject to create auto-backup resources for using `/stash` as `mountPath`", func() { + // Create Secret for BackupBlueprint + cred := f.SecretForLocalBackend() + _, err := f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + f.AppendToCleanupList(&cred) + + // We are going to use an PVC as backend + pvc, err := f.CreateNewPVC(rand.WithUniqSuffix("backend-pvc")) + Expect(err).NotTo(HaveOccurred()) + + // Generate BackupBlueprint definition + bb := f.BackupBlueprint(cred.Name) + bb.Spec.Backend.Local = &store.LocalSpec{ + VolumeSource: core.VolumeSource{ + PersistentVolumeClaim: &core.PersistentVolumeClaimVolumeSource{ + ClaimName: pvc.Name, + }, + }, + MountPath: "/stash", // Use `/stash` as `mountPath`, same thing happened if you use `/stash/data` as `mountPath` + } + + By(fmt.Sprintf("Creating BackupBlueprint: %s", bb.Name)) + createdBB, err := f.CreateBackupBlueprint(bb) + Expect(err).NotTo(HaveOccurred()) + f.AppendToCleanupList(createdBB) + + // Deploy a DaemonSet + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) + Expect(err).NotTo(HaveOccurred()) + + // Add auto-backup annotations to Target + err = f.AddAutoBackupAnnotations(annotations(bb.Name), deployment) + Expect(err).NotTo(HaveOccurred()) + + // AutoBackup Resource creation failed + f.EventuallyEvent(deployment.ObjectMeta, apis.KindDeployment).Should(matcher.HaveEvent(eventer.EventReasonAutoBackupResourcesCreationFailed)) + }) + }) + }) +}) diff --git a/test/e2e/rc_test.go b/test/e2e/rc_test.go index 0521fe21d..c02b3f75b 100644 --- a/test/e2e/rc_test.go +++ b/test/e2e/rc_test.go @@ -83,7 +83,7 @@ var _ = XDescribe("ReplicationController", func() { pvc := f.PersistentVolumeClaim(rand.WithUniqSuffix("pvc")) _, err := f.CreatePersistentVolumeClaim(pvc) Expect(err).NotTo(HaveOccurred()) - rc = f.ReplicationController(pvc.Name) + rc = f.ReplicationController(pvc.Name, framework.SourceVolume) localRef = api.LocalTypedReference{ Kind: apis.KindReplicationController, Name: rc.Name, diff --git a/test/e2e/replicaset_test.go b/test/e2e/replicaset_test.go index a34f7c7b9..1af3220c8 100644 --- a/test/e2e/replicaset_test.go +++ b/test/e2e/replicaset_test.go @@ -85,7 +85,7 @@ var _ = XDescribe("ReplicaSet", func() { pvc := f.PersistentVolumeClaim(rand.WithUniqSuffix("pvc")) _, err := f.CreatePersistentVolumeClaim(pvc) Expect(err).NotTo(HaveOccurred()) - rs = f.ReplicaSet(pvc.Name) + rs = f.ReplicaSet(pvc.Name, framework.SourceVolume) localRef = api.LocalTypedReference{ Kind: apis.KindReplicaSet, Name: rs.Name, diff --git a/test/e2e/snapshots_test.go b/test/e2e/snapshots_test.go index 980dd3df0..e54d4cb75 100644 --- a/test/e2e/snapshots_test.go +++ b/test/e2e/snapshots_test.go @@ -17,6 +17,7 @@ limitations under the License. package e2e_test import ( + "fmt" "net" "os/exec" "strconv" @@ -122,12 +123,12 @@ var _ = XDescribe("Snapshots", func() { pvc := f.PersistentVolumeClaim(rand.WithUniqSuffix("pvc")) _, err := f.CreatePersistentVolumeClaim(pvc) Expect(err).NotTo(HaveOccurred()) - daemon = f.DaemonSet() + daemon = f.DaemonSet(fmt.Sprintf("%s-%s", framework.SourceDaemonSet, f.App()), framework.SourceVolume) - deployment = f.Deployment(pvc.Name) - rc = f.ReplicationController(pvc.Name) - rs = f.ReplicaSet(pvc.Name) - ss = f.StatefulSet(pvc.Name) + deployment = f.Deployment(pvc.Name, framework.SourceVolume) + rc = f.ReplicationController(pvc.Name, framework.SourceVolume) + rs = f.ReplicaSet(pvc.Name, framework.SourceVolume) + ss = f.StatefulSet(pvc.Name, framework.SourceVolume) svc = f.HeadlessService() // if a deployment's labels match to labels of replicaset, kubernetes make the deployment owner of the replicaset. diff --git a/test/e2e/statefulset_test.go b/test/e2e/statefulset_test.go index 87cdbf363..34e877c78 100644 --- a/test/e2e/statefulset_test.go +++ b/test/e2e/statefulset_test.go @@ -89,7 +89,7 @@ var _ = XDescribe("StatefulSet", func() { _, err := f.CreatePersistentVolumeClaim(pvc) Expect(err).NotTo(HaveOccurred()) - ss = f.StatefulSet(pvc.Name) + ss = f.StatefulSet(pvc.Name, framework.SourceVolume) localRef = api.LocalTypedReference{ Kind: apis.KindStatefulSet, Name: ss.Name, diff --git a/test/e2e/volumes/volume.go b/test/e2e/volumes/volume.go index 31cc8affa..2081093ca 100644 --- a/test/e2e/volumes/volume.go +++ b/test/e2e/volumes/volume.go @@ -38,10 +38,7 @@ var _ = Describe("Volume", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -54,7 +51,7 @@ var _ = Describe("Volume", func() { Context("Restore in same PVC", func() { It("should Backup & Restore in the source PVC", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -110,7 +107,7 @@ var _ = Describe("Volume", func() { Context("Restore in different PVC", func() { It("should restore backed up data into different PVC", func() { // Create new PVC - pvc, err := f.CreateNewPVC(fmt.Sprintf("source-pvc1-%s", f.App())) + pvc, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.SourceVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy a Pod @@ -140,7 +137,7 @@ var _ = Describe("Volume", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Create restored Pvc - restoredPVC, err := f.CreateNewPVC(fmt.Sprintf("restore-pvc-%s", f.App())) + restoredPVC, err := f.CreateNewPVC(fmt.Sprintf("%s-%s", framework.RestoredVolume, f.App())) Expect(err).NotTo(HaveOccurred()) // Deploy another Pod @@ -165,7 +162,5 @@ var _ = Describe("Volume", func() { Expect(restoredData).Should(BeSameAs(sampleData)) }) }) - }) - }) diff --git a/test/e2e/workloads/daemonset.go b/test/e2e/workloads/daemonset.go index 1263602bc..b7ef5d549 100644 --- a/test/e2e/workloads/daemonset.go +++ b/test/e2e/workloads/daemonset.go @@ -17,8 +17,6 @@ limitations under the License. package workloads import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("Workload Test", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -54,7 +49,7 @@ var _ = Describe("Workload Test", func() { Context("Restore in same DaemonSet", func() { It("should Backup & Restore in the source DaemonSet", func() { // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("source-daemon1-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -85,7 +80,7 @@ var _ = Describe("Workload Test", func() { // Restore the backed up data By("Restoring the backed up data in the original DaemonSet") - restoreSession, err := f.SetupRestoreProcess(dmn.ObjectMeta, repo, apis.KindDaemonSet) + restoreSession, err := f.SetupRestoreProcess(dmn.ObjectMeta, repo, apis.KindDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -105,7 +100,7 @@ var _ = Describe("Workload Test", func() { Context("Restore in different DaemonSet", func() { It("should restore backed up data into different DaemonSet", func() { // Deploy a DaemonSet - dmn, err := f.DeployDaemonSet(fmt.Sprintf("source-daemon2-%s", f.App())) + dmn, err := f.DeployDaemonSet(framework.SourceDaemonSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -130,12 +125,12 @@ var _ = Describe("Workload Test", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Deploy restored DaemonSet - restoredDmn, err := f.DeployDaemonSet(fmt.Sprintf("restored-daemon-%s", f.App())) + restoredDmn, err := f.DeployDaemonSet(framework.RestoredDaemonSet, framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) // Restore the backed up data By("Restoring the backed up data in different DaemonSet") - restoreSession, err := f.SetupRestoreProcess(restoredDmn.ObjectMeta, repo, apis.KindDaemonSet) + restoreSession, err := f.SetupRestoreProcess(restoredDmn.ObjectMeta, repo, apis.KindDaemonSet, framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") diff --git a/test/e2e/workloads/deployment.go b/test/e2e/workloads/deployment.go index 42a5d02f8..da6ba6c5e 100644 --- a/test/e2e/workloads/deployment.go +++ b/test/e2e/workloads/deployment.go @@ -17,8 +17,6 @@ limitations under the License. package workloads import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("Deployment", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -54,7 +49,7 @@ var _ = Describe("Deployment", func() { Context("Restore in same Deployment", func() { It("should Backup & Restore in the source Deployment", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment1-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -85,7 +80,7 @@ var _ = Describe("Deployment", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -105,7 +100,7 @@ var _ = Describe("Deployment", func() { Context("Restore in different Deployment", func() { It("should restore backed up data into different Deployment", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment2-%s", f.App()), int32(1)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -131,12 +126,12 @@ var _ = Describe("Deployment", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Deploy restored Deployment - restoredDeployment, err := f.DeployDeployment(fmt.Sprintf("restored-deployment-%s", f.App()), int32(1)) + restoredDeployment, err := f.DeployDeployment(framework.RestoredDeployment, int32(1), framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) // Restore the backed up data By("Restoring the backed up data in different Deployment") - restoreSession, err := f.SetupRestoreProcess(restoredDeployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(restoredDeployment.ObjectMeta, repo, apis.KindDeployment, framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -156,7 +151,7 @@ var _ = Describe("Deployment", func() { Context("Leader election for backup and restore Deployment", func() { It("Should leader elect and backup and restore Deployment", func() { // Deploy a Deployment - deployment, err := f.DeployDeployment(fmt.Sprintf("source-deployment3-%s", f.App()), int32(2)) + deployment, err := f.DeployDeployment(framework.SourceDeployment, int32(2), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -190,7 +185,7 @@ var _ = Describe("Deployment", func() { // Restore the backed up data By("Restoring the backed up data in the original Deployment") - restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment) + restoreSession, err := f.SetupRestoreProcess(deployment.ObjectMeta, repo, apis.KindDeployment, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -206,7 +201,5 @@ var _ = Describe("Deployment", func() { Expect(restoredData).Should(BeSameAs(sampleData)) }) }) - }) - }) diff --git a/test/e2e/workloads/replicaset.go b/test/e2e/workloads/replicaset.go index 5e725fbca..38a5d8d40 100644 --- a/test/e2e/workloads/replicaset.go +++ b/test/e2e/workloads/replicaset.go @@ -17,8 +17,6 @@ limitations under the License. package workloads import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("ReplicaSet", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -54,7 +49,7 @@ var _ = Describe("ReplicaSet", func() { Context("Restore in same ReplicaSet", func() { It("should Backup & Restore in the source ReplicaSet", func() { // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("source-rs1-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -85,7 +80,7 @@ var _ = Describe("ReplicaSet", func() { // Restore the backed up data By("Restoring the backed up data in the original ReplicaSet") - restoreSession, err := f.SetupRestoreProcess(rs.ObjectMeta, repo, apis.KindReplicaSet) + restoreSession, err := f.SetupRestoreProcess(rs.ObjectMeta, repo, apis.KindReplicaSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -105,7 +100,7 @@ var _ = Describe("ReplicaSet", func() { Context("Restore in different ReplicaSet", func() { It("should restore backed up data into different ReplicaSet", func() { // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("source-rs2-%s", f.App()), int32(1)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -130,12 +125,12 @@ var _ = Describe("ReplicaSet", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Deploy restored ReplicaSet - restoredRS, err := f.DeployReplicaSet(fmt.Sprintf("restored-rs-%s", f.App()), int32(1)) + restoredRS, err := f.DeployReplicaSet(framework.RestoredReplicaSet, int32(1), framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) // Restore the backed up data By("Restoring the backed up data in different ReplicaSet") - restoreSession, err := f.SetupRestoreProcess(restoredRS.ObjectMeta, repo, apis.KindReplicaSet) + restoreSession, err := f.SetupRestoreProcess(restoredRS.ObjectMeta, repo, apis.KindReplicaSet, framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -155,7 +150,7 @@ var _ = Describe("ReplicaSet", func() { Context("Leader election for backup and restore ReplicaSet", func() { It("Should leader elect and backup and restore ReplicaSet", func() { // Deploy a ReplicaSet - rs, err := f.DeployReplicaSet(fmt.Sprintf("source-rs3-%s", f.App()), int32(2)) + rs, err := f.DeployReplicaSet(framework.SourceReplicaSet, int32(2), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -189,7 +184,7 @@ var _ = Describe("ReplicaSet", func() { // Restore the backed up data By("Restoring the backed up data in the original ReplicaSet") - restoreSession, err := f.SetupRestoreProcess(rs.ObjectMeta, repo, apis.KindReplicaSet) + restoreSession, err := f.SetupRestoreProcess(rs.ObjectMeta, repo, apis.KindReplicaSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -205,7 +200,5 @@ var _ = Describe("ReplicaSet", func() { Expect(restoredData).Should(BeSameAs(sampleData)) }) }) - }) - }) diff --git a/test/e2e/workloads/replicationcontroller.go b/test/e2e/workloads/replicationcontroller.go index 802a4df9c..ba355bd0f 100644 --- a/test/e2e/workloads/replicationcontroller.go +++ b/test/e2e/workloads/replicationcontroller.go @@ -17,8 +17,6 @@ limitations under the License. package workloads import ( - "fmt" - "stash.appscode.dev/stash/apis" "stash.appscode.dev/stash/apis/stash/v1beta1" "stash.appscode.dev/stash/test/e2e/framework" @@ -38,10 +36,7 @@ var _ = Describe("ReplicationController", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -54,7 +49,7 @@ var _ = Describe("ReplicationController", func() { Context("Restore in same ReplicationController", func() { It("should Backup & Restore in the source ReplicationController", func() { // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("source-rc1-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -85,7 +80,7 @@ var _ = Describe("ReplicationController", func() { // Restore the backed up data By("Restoring the backed up data in the original ReplicationController") - restoreSession, err := f.SetupRestoreProcess(rc.ObjectMeta, repo, apis.KindReplicationController) + restoreSession, err := f.SetupRestoreProcess(rc.ObjectMeta, repo, apis.KindReplicationController, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -105,7 +100,7 @@ var _ = Describe("ReplicationController", func() { Context("Restore in different ReplicationController", func() { It("should restore backed up data into different ReplicationController", func() { // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("source-rc2-%s", f.App()), int32(1)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(1), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -130,12 +125,12 @@ var _ = Describe("ReplicationController", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Deploy restored ReplicationController - restoredRC, err := f.DeployReplicationController(fmt.Sprintf("restored-rc-%s", f.App()), int32(1)) + restoredRC, err := f.DeployReplicationController(framework.RestoredReplicationController, int32(1), framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) // Restore the backed up data By("Restoring the backed up data in different ReplicationController") - restoreSession, err := f.SetupRestoreProcess(restoredRC.ObjectMeta, repo, apis.KindReplicationController) + restoreSession, err := f.SetupRestoreProcess(restoredRC.ObjectMeta, repo, apis.KindReplicationController, framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -155,7 +150,7 @@ var _ = Describe("ReplicationController", func() { Context("Leader election for backup and restore ReplicationController", func() { It("Should leader elect and backup and restore ReplicationController", func() { // Deploy a ReplicationController - rc, err := f.DeployReplicationController(fmt.Sprintf("source-rc3-%s", f.App()), int32(2)) + rc, err := f.DeployReplicationController(framework.SourceReplicationController, int32(2), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -189,7 +184,7 @@ var _ = Describe("ReplicationController", func() { // Restore the backed up data By("Restoring the backed up data in the original ReplicationController") - restoreSession, err := f.SetupRestoreProcess(rc.ObjectMeta, repo, apis.KindReplicationController) + restoreSession, err := f.SetupRestoreProcess(rc.ObjectMeta, repo, apis.KindReplicationController, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -205,7 +200,5 @@ var _ = Describe("ReplicationController", func() { Expect(restoredData).Should(BeSameAs(sampleData)) }) }) - }) - }) diff --git a/test/e2e/workloads/statefulset.go b/test/e2e/workloads/statefulset.go index 65da9d296..add816852 100644 --- a/test/e2e/workloads/statefulset.go +++ b/test/e2e/workloads/statefulset.go @@ -17,19 +17,13 @@ limitations under the License. package workloads import ( - "fmt" - "stash.appscode.dev/stash/apis" - api "stash.appscode.dev/stash/apis/stash/v1alpha1" "stash.appscode.dev/stash/apis/stash/v1beta1" - "stash.appscode.dev/stash/pkg/util" "stash.appscode.dev/stash/test/e2e/framework" . "stash.appscode.dev/stash/test/e2e/matcher" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - apps "k8s.io/api/apps/v1" - core "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -42,10 +36,7 @@ var _ = Describe("StatefulSet", func() { }) JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { - f.PrintDebugHelpers() - framework.TestFailed = true - } + f.PrintDebugInfoOnFailure() }) AfterEach(func() { @@ -53,63 +44,12 @@ var _ = Describe("StatefulSet", func() { Expect(err).NotTo(HaveOccurred()) }) - var ( - setupRestoreProcessOnScaledUpSS = func(ss *apps.StatefulSet, repo *api.Repository) (*v1beta1.RestoreSession, error) { - By("Creating RestoreSession") - restoreSession := f.GetRestoreSession(repo.Name, func(restore *v1beta1.RestoreSession) { - restore.Spec.Target = &v1beta1.RestoreTarget{ - Ref: framework.GetTargetRef(ss.Name, apis.KindStatefulSet), - VolumeMounts: []core.VolumeMount{ - { - Name: framework.TestSourceDataVolumeName, - MountPath: framework.TestSourceDataMountPath, - }, - }, - } - restore.Spec.Rules = []v1beta1.Rule{ - { - TargetHosts: []string{ - "host-3", - "host-4", - }, - SourceHost: "host-0", - Paths: []string{ - framework.TestSourceDataMountPath, - }, - }, - { - TargetHosts: []string{}, - Paths: []string{ - framework.TestSourceDataMountPath, - }, - }, - } - }) - - err := f.CreateRestoreSession(restoreSession) - Expect(err).NotTo(HaveOccurred()) - f.AppendToCleanupList(restoreSession) - - By("Verifying that init-container has been injected") - f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveInitContainer(util.StashInitContainer)) - - By("Waiting for StatefulSet to be ready with init-container") - err = f.WaitUntilStatefulSetWithInitContainer(ss.ObjectMeta) - f.EventuallyPodAccessible(ss.ObjectMeta).Should(BeTrue()) - - By("Waiting for restore process to complete") - f.EventuallyRestoreProcessCompleted(restoreSession.ObjectMeta).Should(BeTrue()) - - return restoreSession, err - } - ) - Context("StatefulSet", func() { Context("Restore in same StatefulSet", func() { It("should Backup & Restore in the source StatefulSet", func() { // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("source-ss1-%s", f.App()), int32(3)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(3), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -140,7 +80,7 @@ var _ = Describe("StatefulSet", func() { // Restore the backed up data By("Restoring the backed up data in the original StatefulSet") - restoreSession, err := f.SetupRestoreProcess(ss.ObjectMeta, repo, apis.KindStatefulSet) + restoreSession, err := f.SetupRestoreProcess(ss.ObjectMeta, repo, apis.KindStatefulSet, framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -160,7 +100,7 @@ var _ = Describe("StatefulSet", func() { Context("Restore in different StatefulSet", func() { It("should restore backed up data into different StatefulSet", func() { // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("source-ss2-%s", f.App()), int32(3)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(3), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -185,12 +125,12 @@ var _ = Describe("StatefulSet", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Deploy restored StatefulSet - restoredSS, err := f.DeployStatefulSet(fmt.Sprintf("restored-ss2-%s", f.App()), int32(3)) + restoredSS, err := f.DeployStatefulSet(framework.RestoredStatefulSet, int32(3), framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) // Restore the backed up data - By("Restoring the backed up data in the original StatefulSet") - restoreSession, err := f.SetupRestoreProcess(restoredSS.ObjectMeta, repo, apis.KindStatefulSet) + By("Restoring the backed up data in the new StatefulSet") + restoreSession, err := f.SetupRestoreProcess(restoredSS.ObjectMeta, repo, apis.KindStatefulSet, framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -210,7 +150,7 @@ var _ = Describe("StatefulSet", func() { Context("Restore on scaled up StatefulSet", func() { It("should restore backed up data into scaled up StatefulSet", func() { // Deploy a StatefulSet - ss, err := f.DeployStatefulSet(fmt.Sprintf("source-ss3-%s", f.App()), int32(3)) + ss, err := f.DeployStatefulSet(framework.SourceStatefulSet, int32(3), framework.SourceVolume) Expect(err).NotTo(HaveOccurred()) // Generate Sample Data @@ -235,12 +175,31 @@ var _ = Describe("StatefulSet", func() { Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) // Deploy restored StatefulSet - restoredSS, err := f.DeployStatefulSet(fmt.Sprintf("restored-ss3-%s", f.App()), int32(5)) + restoredSS, err := f.DeployStatefulSet(framework.RestoredStatefulSet, int32(5), framework.RestoredVolume) Expect(err).NotTo(HaveOccurred()) // Restore the backed up data By("Restoring the backed up data in different StatefulSet") - restoreSession, err := setupRestoreProcessOnScaledUpSS(restoredSS, repo) + restoreSession, err := f.SetupRestoreProcess(restoredSS.ObjectMeta, repo, apis.KindStatefulSet, framework.RestoredVolume, func(restore *v1beta1.RestoreSession) { + restore.Spec.Rules = []v1beta1.Rule{ + { + TargetHosts: []string{ + "host-3", + "host-4", + }, + SourceHost: "host-0", + Paths: []string{ + framework.TestSourceDataMountPath, + }, + }, + { + TargetHosts: []string{}, + Paths: []string{ + framework.TestSourceDataMountPath, + }, + }, + } + }) Expect(err).NotTo(HaveOccurred()) By("Verifying that RestoreSession succeeded") @@ -256,7 +215,5 @@ var _ = Describe("StatefulSet", func() { Expect(restoredData).Should(BeSameAs(sampleData)) }) }) - }) - })