Skip to content

Commit

Permalink
Add tests for other workloads
Browse files Browse the repository at this point in the history
  • Loading branch information
diptadas committed Nov 27, 2017
1 parent aadbcbd commit 9f8e607
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 8 deletions.
54 changes: 54 additions & 0 deletions test/e2e/daemonset_test.go
Expand Up @@ -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)))
})
})
})
})
13 changes: 7 additions & 6 deletions test/e2e/deployment_test.go
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_suite_test.go
Expand Up @@ -85,7 +85,7 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
// root.DeleteNamespace()
root.DeleteNamespace()
if createInitConfig {
root.DeleteInitializerConfiguration(root.InitializerForWorkloads().ObjectMeta)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/framework.go
Expand Up @@ -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"),
}
}

Expand Down
32 changes: 32 additions & 0 deletions test/e2e/framework/statefulset.go
Expand Up @@ -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)
}
Expand Down
54 changes: 54 additions & 0 deletions test/e2e/rc_test.go
Expand Up @@ -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)))
})
})
})
})
54 changes: 54 additions & 0 deletions test/e2e/replicaset_test.go
Expand Up @@ -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)))
})
})
})
})
59 changes: 59 additions & 0 deletions test/e2e/statefulset_test.go
Expand Up @@ -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)))
})
})
})
})

0 comments on commit 9f8e607

Please sign in to comment.