From 9f8e607808b9d576e0c830b74d46515bf2b265c9 Mon Sep 17 00:00:00 2001 From: diptadas Date: Mon, 27 Nov 2017 17:53:28 +0600 Subject: [PATCH] Add tests for other workloads --- test/e2e/daemonset_test.go | 54 ++++++++++++++++++++++++++++ test/e2e/deployment_test.go | 13 +++---- test/e2e/e2e_suite_test.go | 2 +- test/e2e/framework/framework.go | 2 +- test/e2e/framework/statefulset.go | 32 +++++++++++++++++ test/e2e/rc_test.go | 54 ++++++++++++++++++++++++++++ test/e2e/replicaset_test.go | 54 ++++++++++++++++++++++++++++ test/e2e/statefulset_test.go | 59 +++++++++++++++++++++++++++++++ 8 files changed, 262 insertions(+), 8 deletions(-) diff --git a/test/e2e/daemonset_test.go b/test/e2e/daemonset_test.go index 95d66ba19..29396000c 100644 --- a/test/e2e/daemonset_test.go +++ b/test/e2e/daemonset_test.go @@ -408,4 +408,58 @@ var _ = Describe("DaemonSet", func() { It("should initialize and backup new DaemonSet", shouldInitializeAndBackupDaemonSet) }) }) + + Describe("Offline backup for", func() { + AfterEach(func() { + f.DeleteDaemonSet(daemon.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + framework.CleanupMinikubeHostPath() + }) + + Context(`"Local" backend`, func() { + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForHostPathLocalBackend() + restic.Spec.Type = api.BackupOffline + restic.Spec.Schedule = "*/5 * * * *" + }) + It(`should backup new DaemonSet`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic " + restic.Name) + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + cronJobName := util.KubectlCronPrefix + restic.Name + By("Checking cron job created: " + cronJobName) + Eventually(func() error { + _, err := f.KubeClient.BatchV1beta1().CronJobs(restic.Namespace).Get(cronJobName, metav1.GetOptions{}) + return err + }).Should(BeNil()) + + By("Creating DaemonSet " + daemon.Name) + _, err = f.CreateDaemonSet(daemon) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for init-container") + f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + + By("Waiting for initial backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for next backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 2))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", 1))) + }) + }) + }) }) diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index 263512a98..a9f44a68f 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -502,12 +502,13 @@ var _ = Describe("Deployment", func() { }) }) - FDescribe("Offline backup for", func() { - //AfterEach(func() { - // f.DeleteDeployment(deployment.ObjectMeta) - // f.DeleteRestic(restic.ObjectMeta) - // f.DeleteSecret(cred.ObjectMeta) - //}) + Describe("Offline backup for", func() { + AfterEach(func() { + f.DeleteDeployment(deployment.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + framework.CleanupMinikubeHostPath() + }) Context(`"Local" backend`, func() { BeforeEach(func() { diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index a0c39a6b7..7ffb67cdf 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -85,7 +85,7 @@ var _ = BeforeSuite(func() { }) var _ = AfterSuite(func() { - // root.DeleteNamespace() + root.DeleteNamespace() if createInitConfig { root.DeleteInitializerConfiguration(root.InitializerForWorkloads().ObjectMeta) } diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 84dddd8e8..6455a88dc 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -16,7 +16,7 @@ func New(kubeClient kubernetes.Interface, extClient cs.StashV1alpha1Interface) * return &Framework{ KubeClient: kubeClient, StashClient: extClient, - namespace: "test-stash", //rand.WithUniqSuffix("test-stash"), + namespace: rand.WithUniqSuffix("test-stash"), } } diff --git a/test/e2e/framework/statefulset.go b/test/e2e/framework/statefulset.go index 32ce5fb3f..cc7a87895 100644 --- a/test/e2e/framework/statefulset.go +++ b/test/e2e/framework/statefulset.go @@ -43,6 +43,38 @@ func (fi *Invocation) StatefulSet(r api.Restic, sidecarImageTag string) apps.Sta return resource } +func (fi *Invocation) StatefulSetWitInitContainer(r api.Restic, sidecarImageTag string) apps.StatefulSet { + resource := apps.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: rand.WithUniqSuffix("stash"), + Namespace: r.Namespace, + Labels: map[string]string{ + "app": fi.app, + }, + }, + Spec: apps.StatefulSetSpec{ + Replicas: types.Int32P(1), + Template: fi.PodTemplate(), + ServiceName: TEST_HEADLESS_SERVICE, + UpdateStrategy: apps.StatefulSetUpdateStrategy{ + Type: apps.RollingUpdateStatefulSetStrategyType, + }, + }, + } + + workload := api.LocalTypedReference{ + Kind: api.KindStatefulSet, + Name: resource.Name, + } + resource.Spec.Template.Spec.InitContainers = append(resource.Spec.Template.Spec.InitContainers, util.CreateInitContainer(&r, sidecarImageTag, workload)) + resource.Spec.Template.Spec.Volumes = util.UpsertScratchVolume(resource.Spec.Template.Spec.Volumes) + resource.Spec.Template.Spec.Volumes = util.UpsertDownwardVolume(resource.Spec.Template.Spec.Volumes) + if r.Spec.Backend.Local != nil { + resource.Spec.Template.Spec.Volumes = append(resource.Spec.Template.Spec.Volumes, core.Volume{Name: util.LocalVolumeName, VolumeSource: r.Spec.Backend.Local.VolumeSource}) + } + return resource +} + func (f *Framework) CreateStatefulSet(obj apps.StatefulSet) (*apps.StatefulSet, error) { return f.KubeClient.AppsV1beta1().StatefulSets(obj.Namespace).Create(&obj) } diff --git a/test/e2e/rc_test.go b/test/e2e/rc_test.go index 50b386640..a819ed628 100644 --- a/test/e2e/rc_test.go +++ b/test/e2e/rc_test.go @@ -451,4 +451,58 @@ var _ = Describe("ReplicationController", func() { It("should initialize and backup new RC", shouldInitializeAndBackupRC) }) }) + + Describe("Offline backup for", func() { + AfterEach(func() { + f.DeleteReplicationController(rc.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + framework.CleanupMinikubeHostPath() + }) + + Context(`"Local" backend`, func() { + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForHostPathLocalBackend() + restic.Spec.Type = api.BackupOffline + restic.Spec.Schedule = "*/5 * * * *" + }) + It(`should backup new RC`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic " + restic.Name) + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + cronJobName := util.KubectlCronPrefix + restic.Name + By("Checking cron job created: " + cronJobName) + Eventually(func() error { + _, err := f.KubeClient.BatchV1beta1().CronJobs(restic.Namespace).Get(cronJobName, metav1.GetOptions{}) + return err + }).Should(BeNil()) + + By("Creating rc " + rc.Name) + _, err = f.CreateReplicationController(rc) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for init-container") + f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + + By("Waiting for initial backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for next backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 2))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", 1))) + }) + }) + }) }) diff --git a/test/e2e/replicaset_test.go b/test/e2e/replicaset_test.go index 0e4f2f5ff..7853d0bd3 100644 --- a/test/e2e/replicaset_test.go +++ b/test/e2e/replicaset_test.go @@ -452,4 +452,58 @@ var _ = Describe("ReplicaSet", func() { It("should initialize and backup new ReplicaSet", shouldInitializeAndBackupReplicaSet) }) }) + + Describe("Offline backup for", func() { + AfterEach(func() { + f.DeleteReplicaSet(rs.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + framework.CleanupMinikubeHostPath() + }) + + Context(`"Local" backend`, func() { + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForHostPathLocalBackend() + restic.Spec.Type = api.BackupOffline + restic.Spec.Schedule = "*/5 * * * *" + }) + It(`should backup new RS`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic " + restic.Name) + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + cronJobName := util.KubectlCronPrefix + restic.Name + By("Checking cron job created: " + cronJobName) + Eventually(func() error { + _, err := f.KubeClient.BatchV1beta1().CronJobs(restic.Namespace).Get(cronJobName, metav1.GetOptions{}) + return err + }).Should(BeNil()) + + By("Creating RS " + rs.Name) + _, err = f.CreateReplicaSet(rs) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for init-container") + f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + + By("Waiting for initial backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for next backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 2))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", 1))) + }) + }) + }) }) diff --git a/test/e2e/statefulset_test.go b/test/e2e/statefulset_test.go index dc181d855..0c5e21753 100644 --- a/test/e2e/statefulset_test.go +++ b/test/e2e/statefulset_test.go @@ -438,4 +438,63 @@ var _ = Describe("StatefulSet", func() { It("should initialize and backup new StatefulSet", shouldInitializeAndBackupStatefulSet) }) }) + + Describe("Offline backup for", func() { + AfterEach(func() { + f.DeleteStatefulSet(ss.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + framework.CleanupMinikubeHostPath() + }) + + Context(`"Local" backend`, func() { + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForHostPathLocalBackend() + restic.Spec.Type = api.BackupOffline + restic.Spec.Schedule = "*/5 * * * *" + }) + It(`should backup new StatefulSet`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic " + restic.Name) + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + cronJobName := util.KubectlCronPrefix + restic.Name + By("Checking cron job created: " + cronJobName) + Eventually(func() error { + _, err := f.KubeClient.BatchV1beta1().CronJobs(restic.Namespace).Get(cronJobName, metav1.GetOptions{}) + return err + }).Should(BeNil()) + + By("Creating service " + svc.Name) + err = f.CreateService(svc) + Expect(err).NotTo(HaveOccurred()) + + By("Creating StatefulSet " + ss.Name) + ss = f.StatefulSetWitInitContainer(restic, TestSidecarImageTag) + _, err = f.CreateStatefulSet(ss) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for init-container") + f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + + By("Waiting for initial backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for next backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 2))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", 1))) + }) + }) + }) })