From a61bc2e3db6e78559ea51ad57972638d63f86a5a Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Sun, 25 Mar 2018 11:46:23 +0600 Subject: [PATCH 01/11] create repository crd for each restic repository --- apis/stash/v1alpha1/crd.go | 2 +- apis/stash/v1alpha1/crds.yaml | 54 +++++++++++++++++++++++------------ hack/deploy/operator.yaml | 2 +- pkg/backup/backup.go | 3 ++ pkg/backup/repository.go | 42 +++++++++++++++++++++++++++ pkg/controller/controller.go | 1 + 6 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 pkg/backup/repository.go diff --git a/apis/stash/v1alpha1/crd.go b/apis/stash/v1alpha1/crd.go index b430eeb2b..001144cb2 100644 --- a/apis/stash/v1alpha1/crd.go +++ b/apis/stash/v1alpha1/crd.go @@ -60,7 +60,7 @@ func (c Repository) CustomResourceDefinition() *apiextensions.CustomResourceDefi Singular: ResourceNameRepository, Plural: ResourceTypeRepository, Kind: ResourceKindRepository, - ShortNames: []string{"rec"}, + ShortNames: []string{"repo"}, }, }, } diff --git a/apis/stash/v1alpha1/crds.yaml b/apis/stash/v1alpha1/crds.yaml index 8a3108bec..26ed7cfb6 100644 --- a/apis/stash/v1alpha1/crds.yaml +++ b/apis/stash/v1alpha1/crds.yaml @@ -15,21 +15,39 @@ spec: singular: restic scope: Namespaced version: v1alpha1 - --- - apiVersion: apiextensions.k8s.io/v1beta1 - kind: CustomResourceDefinition - metadata: - name: recoveries.stash.appscode.com - labels: - app: stash - spec: - group: stash.appscode.com - names: - kind: Recovery - listKind: RecoveryList - plural: recoveries - shortNames: - - rec - singular: recovery - scope: Namespaced - version: v1alpha1 \ No newline at end of file +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: recoveries.stash.appscode.com + labels: + app: stash +spec: + group: stash.appscode.com + names: + kind: Recovery + listKind: RecoveryList + plural: recoveries + shortNames: + - rec + singular: recovery + scope: Namespaced + version: v1alpha1 +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: repositories.stash.appscode.com + labels: + app: stash +spec: + group: stash.appscode.com + names: + kind: Repository + listKind: RepositoryList + plural: repositories + shortNames: + - repo + singular: repository + scope: Namespaced + version: v1alpha1 \ No newline at end of file diff --git a/hack/deploy/operator.yaml b/hack/deploy/operator.yaml index e494fa238..1e6c971ad 100644 --- a/hack/deploy/operator.yaml +++ b/hack/deploy/operator.yaml @@ -31,7 +31,7 @@ spec: - --tls-cert-file=/var/serving-cert/tls.crt - --tls-private-key-file=/var/serving-cert/tls.key - --enable-analytics=${STASH_ENABLE_ANALYTICS} - image: ${STASH_DOCKER_REGISTRY}/stash:0.7.0-rc.2 + image: ${STASH_DOCKER_REGISTRY}/stash:repository ports: - containerPort: 8443 - containerPort: 56790 diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index c0549562c..ac55f12b5 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -224,6 +224,9 @@ func (c *Controller) setup() (*api.Restic, error) { if err = c.resticCLI.InitRepositoryIfAbsent(); err != nil { return resource, err } + if err = c.createRepositoryCrdIfNotExist(resource); err != nil { + return resource, err + } return resource, nil } diff --git a/pkg/backup/repository.go b/pkg/backup/repository.go new file mode 100644 index 000000000..73039e30e --- /dev/null +++ b/pkg/backup/repository.go @@ -0,0 +1,42 @@ +package backup + +import ( + "strings" + + "github.com/appscode/go/log" + api "github.com/appscode/stash/apis/stash/v1alpha1" + kerr "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func (c *Controller) createRepositoryCrdIfNotExist(restic *api.Restic) error { + repository := &api.Repository{} + switch c.opt.Workload.Kind { + case api.KindDeployment, api.KindReplicaSet, api.KindReplicationController: + repository.Name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.Workload.Name + case api.KindStatefulSet: + repository.Name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.PodName + case api.KindDaemonSet: + repository.Name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.Workload.Name + "." + c.opt.NodeName + } + + repository.Namespace = restic.Namespace + _, err := c.stashClient.StashV1alpha1().Repositories(repository.Namespace).Get(repository.Name, metav1.GetOptions{}) + if err != nil && kerr.IsNotFound(err) { + repository.Labels = map[string]string{ + "restic": restic.Name, + "workload-kind": c.opt.Workload.Kind, + "workload-name": c.opt.Workload.Name, + "node-name": c.opt.NodeName, + "pod-name": c.opt.PodName, + } + + repository.Spec.Backend = restic.Spec.Backend + _, err = c.stashClient.StashV1alpha1().Repositories(repository.Namespace).Create(repository) + if err==nil{ + log.Infof("Repository %v created",repository.Name) + } + return err + } + return err +} diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 0c8ffd867..73fb07016 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -86,6 +86,7 @@ func (c *StashController) ensureCustomResourceDefinitions() error { crds := []*crd_api.CustomResourceDefinition{ api.Restic{}.CustomResourceDefinition(), api.Recovery{}.CustomResourceDefinition(), + api.Repository{}.CustomResourceDefinition(), } return apiext_util.RegisterCRDs(c.crdClient, crds) } From 355a28e14758943517cb4f07eb8ee618eb3c1644 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Sun, 25 Mar 2018 11:59:21 +0600 Subject: [PATCH 02/11] fixed labels --- pkg/backup/repository.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/backup/repository.go b/pkg/backup/repository.go index 73039e30e..29ba999db 100644 --- a/pkg/backup/repository.go +++ b/pkg/backup/repository.go @@ -27,14 +27,23 @@ func (c *Controller) createRepositoryCrdIfNotExist(restic *api.Restic) error { "restic": restic.Name, "workload-kind": c.opt.Workload.Kind, "workload-name": c.opt.Workload.Name, - "node-name": c.opt.NodeName, - "pod-name": c.opt.PodName, + } + + switch c.opt.Workload.Kind { + case api.KindStatefulSet: + repository.Labels = map[string]string{ + "pod-name": c.opt.PodName, + } + case api.KindDaemonSet: + repository.Labels = map[string]string{ + "node-name": c.opt.NodeName, + } } repository.Spec.Backend = restic.Spec.Backend _, err = c.stashClient.StashV1alpha1().Repositories(repository.Namespace).Create(repository) - if err==nil{ - log.Infof("Repository %v created",repository.Name) + if err == nil { + log.Infof("Repository %v created", repository.Name) } return err } From 79c59b1ff5aa11f778023ff7baf5c4fca7a52f57 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Sun, 25 Mar 2018 13:57:05 +0600 Subject: [PATCH 03/11] Added test for DaemonSet --- test/e2e/daemonset_test.go | 43 +++++++++++++++++++++++++++ test/e2e/e2e_suite_test.go | 2 +- test/e2e/framework/repository.go | 50 ++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 test/e2e/framework/repository.go diff --git a/test/e2e/daemonset_test.go b/test/e2e/daemonset_test.go index a59c51fb3..c6feeae77 100644 --- a/test/e2e/daemonset_test.go +++ b/test/e2e/daemonset_test.go @@ -674,4 +674,47 @@ var _ = Describe("DaemonSet", func() { }) }) + Describe("Repository CRD", func() { + Context(`"Local" backend`, func() { + AfterEach(func() { + f.DeleteDaemonSet(daemon.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + f.DeleteRepositories() + }) + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForLocalBackend() + }) + It(`should create Repository CRD`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic") + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + By("Creating Daemonset " + daemon.Name) + _, err = f.CreateDaemonSet(daemon) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for sidecar") + f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet,daemon.ObjectMeta,1).ShouldNot(BeEmpty()) + + By("Waiting for backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) + + }) + + }) + }) }) diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 4ecd4eb7c..7a4554ca4 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -23,7 +23,7 @@ import ( const ( TIMEOUT = 20 * time.Minute - TestStashImageTag = "webhookOR" + TestStashImageTag = "repository" ) var ( diff --git a/test/e2e/framework/repository.go b/test/e2e/framework/repository.go new file mode 100644 index 000000000..dc0228848 --- /dev/null +++ b/test/e2e/framework/repository.go @@ -0,0 +1,50 @@ +package framework + +import ( + "os" + "strconv" + "strings" + + "github.com/appscode/go/log" + api "github.com/appscode/stash/apis/stash/v1alpha1" + . "github.com/onsi/gomega" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func (f *Framework) EventuallyRepository(kind string, objMeta metav1.ObjectMeta, replicas int) GomegaAsyncAssertion { + return Eventually(func() []*api.Repository { + repoNames := make([]string, 0) + switch kind { + case api.KindDeployment, api.KindReplicationController, api.KindReplicaSet: + repoNames = append(repoNames, strings.ToLower(kind)+"."+objMeta.Name) + case api.KindStatefulSet: + for i := 0; i < replicas; i++ { + repoNames = append(repoNames, strings.ToLower(kind)+"."+objMeta.Name+"-"+strconv.Itoa(i)) + } + case api.KindDaemonSet: + nodeName := os.Getenv("NODE_NAME") + if nodeName == "" { + nodeName = "minikube" + } + repoNames = append(repoNames, strings.ToLower(kind)+"."+objMeta.Name+"."+nodeName) + } + repositories := make([]*api.Repository, 0) + for _, repoName := range repoNames { + obj, _ := f.StashClient.StashV1alpha1().Repositories(objMeta.Namespace).Get(repoName, metav1.GetOptions{}) + + repositories = append(repositories, obj) + } + return repositories + }) +} + +func (f *Framework) DeleteRepositories() { + repoList, err := f.StashClient.StashV1alpha1().Repositories(f.namespace).List(metav1.ListOptions{}) + if err != nil { + log.Infof(err.Error()) + return + } + for _, repo := range repoList.Items { + f.StashClient.StashV1alpha1().Repositories(repo.Namespace).Delete(repo.Name, deleteInBackground()) + } +} From 8a159f1926f4e31c6ca0f30cc1fa087d98b6acf3 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Sun, 25 Mar 2018 14:55:43 +0600 Subject: [PATCH 04/11] Test for Repository CRD(Deployment+DaemonSet+RC+RS+SS done) --- test/e2e/daemonset_test.go | 2 +- test/e2e/deployment_test.go | 44 +++++++++++++++ test/e2e/framework/repository.go | 7 ++- test/e2e/rc_test.go | 44 +++++++++++++++ test/e2e/replicaset_test.go | 42 ++++++++++++++ test/e2e/statefulset_test.go | 96 ++++++++++++++++++++++++++++++++ 6 files changed, 231 insertions(+), 4 deletions(-) diff --git a/test/e2e/daemonset_test.go b/test/e2e/daemonset_test.go index c6feeae77..c2295bd18 100644 --- a/test/e2e/daemonset_test.go +++ b/test/e2e/daemonset_test.go @@ -703,7 +703,7 @@ var _ = Describe("DaemonSet", func() { f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) By("Waiting for Repository CRD") - f.EventuallyRepository(api.KindDaemonSet,daemon.ObjectMeta,1).ShouldNot(BeEmpty()) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) By("Waiting for backup to complete") f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index b16d0abd9..93fee56ea 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -983,4 +983,48 @@ var _ = Describe("Deployment", func() { }) }) + + Describe("Repository CRD", func() { + Context(`"Local" backend`, func() { + AfterEach(func() { + f.DeleteDeployment(deployment.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + f.DeleteRepositories() + }) + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForLocalBackend() + }) + It(`should create Repository CRD`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic") + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + By("Creating Deployment " + deployment.Name) + _, err = f.CreateDeployment(deployment) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for sidecar") + f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, 1).ShouldNot(BeEmpty()) + + By("Waiting for backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) + + }) + + }) + }) }) diff --git a/test/e2e/framework/repository.go b/test/e2e/framework/repository.go index dc0228848..358e91203 100644 --- a/test/e2e/framework/repository.go +++ b/test/e2e/framework/repository.go @@ -30,9 +30,10 @@ func (f *Framework) EventuallyRepository(kind string, objMeta metav1.ObjectMeta, } repositories := make([]*api.Repository, 0) for _, repoName := range repoNames { - obj, _ := f.StashClient.StashV1alpha1().Repositories(objMeta.Namespace).Get(repoName, metav1.GetOptions{}) - - repositories = append(repositories, obj) + obj, err := f.StashClient.StashV1alpha1().Repositories(objMeta.Namespace).Get(repoName, metav1.GetOptions{}) + if err == nil { + repositories = append(repositories, obj) + } } return repositories }) diff --git a/test/e2e/rc_test.go b/test/e2e/rc_test.go index 46d644ca5..c4ec0b4d8 100644 --- a/test/e2e/rc_test.go +++ b/test/e2e/rc_test.go @@ -773,4 +773,48 @@ var _ = Describe("ReplicationController", func() { }) }) + + Describe("Create Repository CRD", func() { + Context(`"Local" backend`, func() { + AfterEach(func() { + f.DeleteReplicationController(rc.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + f.DeleteRepositories() + }) + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForLocalBackend() + }) + It(`should create Repository CRD`, 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()) + + By("Creating ReplicationController " + rc.Name) + _, err = f.CreateReplicationController(rc) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for sidecar") + f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, 1).ShouldNot(BeEmpty()) + + By("Waiting for backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + 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 f6cbf4fb3..37ada7368 100644 --- a/test/e2e/replicaset_test.go +++ b/test/e2e/replicaset_test.go @@ -772,4 +772,46 @@ var _ = Describe("ReplicaSet", func() { }) }) + Describe("Create Repository CRD", func() { + Context(`"Local" backend`, func() { + AfterEach(func() { + f.DeleteReplicaSet(rs.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + f.DeleteRepositories() + }) + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForLocalBackend() + }) + It(`should create Repository CRD`, 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()) + + By("Creating ReplicaSet " + rs.Name) + _, err = f.CreateReplicaSet(rs) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for sidecar") + f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, 1).ShouldNot(BeEmpty()) + + By("Waiting for backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + 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 ae9080349..760c51c98 100644 --- a/test/e2e/statefulset_test.go +++ b/test/e2e/statefulset_test.go @@ -3,6 +3,7 @@ package e2e_test import ( "time" + "github.com/appscode/go/types" apps_util "github.com/appscode/kutil/apps/v1beta1" api "github.com/appscode/stash/apis/stash/v1alpha1" "github.com/appscode/stash/pkg/util" @@ -734,4 +735,99 @@ var _ = Describe("StatefulSet", func() { }) }) + Describe("Create Repository CRD", func() { + Context(`"Local" backend, single replica`, func() { + AfterEach(func() { + f.DeleteStatefulSet(ss.ObjectMeta) + f.DeleteService(svc.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + f.DeleteRepositories() + }) + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForLocalBackend() + }) + It(`create`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic") + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + By("Creating service " + svc.Name) + err = f.CreateService(svc) + Expect(err).NotTo(HaveOccurred()) + + By("Creating StatefulSet " + ss.Name) + _, err = f.CreateStatefulSet(ss) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for sidecar") + f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, 1).ShouldNot(BeEmpty()) + + By("Waiting for backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) + }) + + }) + Context(`"Local" backend, multiple replica`, func() { + AfterEach(func() { + f.DeleteStatefulSet(ss.ObjectMeta) + f.DeleteService(svc.ObjectMeta) + f.DeleteRestic(restic.ObjectMeta) + f.DeleteSecret(cred.ObjectMeta) + f.DeleteRepositories() + }) + BeforeEach(func() { + cred = f.SecretForLocalBackend() + restic = f.ResticForLocalBackend() + }) + It(`create`, func() { + By("Creating repository Secret " + cred.Name) + err = f.CreateSecret(cred) + Expect(err).NotTo(HaveOccurred()) + + By("Creating restic") + err = f.CreateRestic(restic) + Expect(err).NotTo(HaveOccurred()) + + By("Creating service " + svc.Name) + err = f.CreateService(svc) + Expect(err).NotTo(HaveOccurred()) + + By("Creating StatefulSet with 3 replica" + ss.Name) + ss.Spec.Replicas = types.Int32P(3) + _, err = f.CreateStatefulSet(ss) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting for sidecar") + f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + + By("Waiting for backup to complete") + f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { + return r.Status.BackupCount + }, BeNumerically(">=", 1))) + + By("Waiting for backup event") + f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) + }) + + }) + }) }) From b79aa0e0702707b3748d8a47a8cb907e53a06ffe Mon Sep 17 00:00:00 2001 From: tamal Date: Sun, 25 Mar 2018 07:16:08 -0700 Subject: [PATCH 05/11] Remove Status from Restic and move to Repository --- .../v1alpha1/zz_generated.conversion.go | 3 +- apis/stash/v1alpha1/types.go | 14 ++-- apis/stash/v1alpha1/zz_generated.deepcopy.go | 73 +++++++------------ client/informers/externalversions/factory.go | 7 +- client/informers/externalversions/generic.go | 1 - .../internalinterfaces/factory_interfaces.go | 3 +- .../stash/v1alpha1/recovery.go | 3 +- .../stash/v1alpha1/repository.go | 3 +- .../externalversions/stash/v1alpha1/restic.go | 3 +- 9 files changed, 41 insertions(+), 69 deletions(-) diff --git a/apis/repositories/v1alpha1/zz_generated.conversion.go b/apis/repositories/v1alpha1/zz_generated.conversion.go index 6da769803..a389c3828 100644 --- a/apis/repositories/v1alpha1/zz_generated.conversion.go +++ b/apis/repositories/v1alpha1/zz_generated.conversion.go @@ -21,11 +21,10 @@ limitations under the License. package v1alpha1 import ( - unsafe "unsafe" - repositories "github.com/appscode/stash/apis/repositories" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" + unsafe "unsafe" ) func init() { diff --git a/apis/stash/v1alpha1/types.go b/apis/stash/v1alpha1/types.go index 2cb8f41aa..5c7638174 100644 --- a/apis/stash/v1alpha1/types.go +++ b/apis/stash/v1alpha1/types.go @@ -23,7 +23,6 @@ type Restic struct { metav1.TypeMeta `json:",inline,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"` Spec ResticSpec `json:"spec,omitempty"` - Status ResticStatus `json:"status,omitempty"` } type ResticSpec struct { @@ -49,14 +48,6 @@ type ResticSpec struct { ImagePullSecrets []core.LocalObjectReference `json:"imagePullSecrets,omitempty"` } -type ResticStatus struct { - FirstBackupTime *metav1.Time `json:"firstBackupTime,omitempty"` - LastBackupTime *metav1.Time `json:"lastBackupTime,omitempty"` - LastSuccessfulBackupTime *metav1.Time `json:"lastSuccessfulBackupTime,omitempty"` - LastBackupDuration string `json:"lastBackupDuration,omitempty"` - BackupCount int64 `json:"backupCount,omitempty"` -} - // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type ResticList struct { @@ -243,6 +234,11 @@ type RepositorySpec struct { } type RepositoryStatus struct { + FirstBackupTime *metav1.Time `json:"firstBackupTime,omitempty"` + LastBackupTime *metav1.Time `json:"lastBackupTime,omitempty"` + LastSuccessfulBackupTime *metav1.Time `json:"lastSuccessfulBackupTime,omitempty"` + LastBackupDuration string `json:"lastBackupDuration,omitempty"` + BackupCount int64 `json:"backupCount,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/apis/stash/v1alpha1/zz_generated.deepcopy.go b/apis/stash/v1alpha1/zz_generated.deepcopy.go index aba22dec2..14c187f9f 100644 --- a/apis/stash/v1alpha1/zz_generated.deepcopy.go +++ b/apis/stash/v1alpha1/zz_generated.deepcopy.go @@ -323,7 +323,7 @@ func (in *Repository) DeepCopyInto(out *Repository) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) return } @@ -400,6 +400,33 @@ func (in *RepositorySpec) DeepCopy() *RepositorySpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RepositoryStatus) DeepCopyInto(out *RepositoryStatus) { *out = *in + if in.FirstBackupTime != nil { + in, out := &in.FirstBackupTime, &out.FirstBackupTime + if *in == nil { + *out = nil + } else { + *out = new(meta_v1.Time) + (*in).DeepCopyInto(*out) + } + } + if in.LastBackupTime != nil { + in, out := &in.LastBackupTime, &out.LastBackupTime + if *in == nil { + *out = nil + } else { + *out = new(meta_v1.Time) + (*in).DeepCopyInto(*out) + } + } + if in.LastSuccessfulBackupTime != nil { + in, out := &in.LastSuccessfulBackupTime, &out.LastSuccessfulBackupTime + if *in == nil { + *out = nil + } else { + *out = new(meta_v1.Time) + (*in).DeepCopyInto(*out) + } + } return } @@ -435,7 +462,6 @@ func (in *Restic) DeepCopyInto(out *Restic) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) return } @@ -537,49 +563,6 @@ func (in *ResticSpec) DeepCopy() *ResticSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResticStatus) DeepCopyInto(out *ResticStatus) { - *out = *in - if in.FirstBackupTime != nil { - in, out := &in.FirstBackupTime, &out.FirstBackupTime - if *in == nil { - *out = nil - } else { - *out = new(meta_v1.Time) - (*in).DeepCopyInto(*out) - } - } - if in.LastBackupTime != nil { - in, out := &in.LastBackupTime, &out.LastBackupTime - if *in == nil { - *out = nil - } else { - *out = new(meta_v1.Time) - (*in).DeepCopyInto(*out) - } - } - if in.LastSuccessfulBackupTime != nil { - in, out := &in.LastSuccessfulBackupTime, &out.LastSuccessfulBackupTime - if *in == nil { - *out = nil - } else { - *out = new(meta_v1.Time) - (*in).DeepCopyInto(*out) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResticStatus. -func (in *ResticStatus) DeepCopy() *ResticStatus { - if in == nil { - return nil - } - out := new(ResticStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RestoreStats) DeepCopyInto(out *RestoreStats) { *out = *in diff --git a/client/informers/externalversions/factory.go b/client/informers/externalversions/factory.go index e2066ded2..30771ee16 100644 --- a/client/informers/externalversions/factory.go +++ b/client/informers/externalversions/factory.go @@ -19,10 +19,6 @@ limitations under the License. package externalversions import ( - reflect "reflect" - sync "sync" - time "time" - versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" stash "github.com/appscode/stash/client/informers/externalversions/stash" @@ -30,6 +26,9 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" + reflect "reflect" + sync "sync" + time "time" ) type sharedInformerFactory struct { diff --git a/client/informers/externalversions/generic.go b/client/informers/externalversions/generic.go index 033ac0edc..ff0a584c9 100644 --- a/client/informers/externalversions/generic.go +++ b/client/informers/externalversions/generic.go @@ -20,7 +20,6 @@ package externalversions import ( "fmt" - v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" diff --git a/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/client/informers/externalversions/internalinterfaces/factory_interfaces.go index 72b87b052..e96d6aeff 100644 --- a/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -19,12 +19,11 @@ limitations under the License. package internalinterfaces import ( - time "time" - versioned "github.com/appscode/stash/client/clientset/versioned" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" + time "time" ) type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer diff --git a/client/informers/externalversions/stash/v1alpha1/recovery.go b/client/informers/externalversions/stash/v1alpha1/recovery.go index 84d383df6..811fd108c 100644 --- a/client/informers/externalversions/stash/v1alpha1/recovery.go +++ b/client/informers/externalversions/stash/v1alpha1/recovery.go @@ -19,8 +19,6 @@ limitations under the License. package v1alpha1 import ( - time "time" - stash_v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" @@ -29,6 +27,7 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" + time "time" ) // RecoveryInformer provides access to a shared informer and lister for diff --git a/client/informers/externalversions/stash/v1alpha1/repository.go b/client/informers/externalversions/stash/v1alpha1/repository.go index 02d82ae99..57f1371fe 100644 --- a/client/informers/externalversions/stash/v1alpha1/repository.go +++ b/client/informers/externalversions/stash/v1alpha1/repository.go @@ -19,8 +19,6 @@ limitations under the License. package v1alpha1 import ( - time "time" - stash_v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" @@ -29,6 +27,7 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" + time "time" ) // RepositoryInformer provides access to a shared informer and lister for diff --git a/client/informers/externalversions/stash/v1alpha1/restic.go b/client/informers/externalversions/stash/v1alpha1/restic.go index a48cabe3d..52c6fa535 100644 --- a/client/informers/externalversions/stash/v1alpha1/restic.go +++ b/client/informers/externalversions/stash/v1alpha1/restic.go @@ -19,8 +19,6 @@ limitations under the License. package v1alpha1 import ( - time "time" - stash_v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" @@ -29,6 +27,7 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" + time "time" ) // ResticInformer provides access to a shared informer and lister for From 40f0b9944cc4a3a16caf88976fd94ed7a7a51df4 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Tue, 27 Mar 2018 12:09:44 +0600 Subject: [PATCH 06/11] Update Repository.Status instead of Restic.Status --- .../v1alpha1/zz_generated.conversion.go | 3 ++- apis/stash/v1alpha1/types.go | 2 +- client/informers/externalversions/factory.go | 7 +++--- client/informers/externalversions/generic.go | 1 + .../internalinterfaces/factory_interfaces.go | 3 ++- .../stash/v1alpha1/recovery.go | 3 ++- .../stash/v1alpha1/repository.go | 3 ++- .../externalversions/stash/v1alpha1/restic.go | 3 ++- pkg/backup/backup.go | 7 ++++-- pkg/backup/repository.go | 24 ++++++++++++------- 10 files changed, 36 insertions(+), 20 deletions(-) diff --git a/apis/repositories/v1alpha1/zz_generated.conversion.go b/apis/repositories/v1alpha1/zz_generated.conversion.go index a389c3828..6da769803 100644 --- a/apis/repositories/v1alpha1/zz_generated.conversion.go +++ b/apis/repositories/v1alpha1/zz_generated.conversion.go @@ -21,10 +21,11 @@ limitations under the License. package v1alpha1 import ( + unsafe "unsafe" + repositories "github.com/appscode/stash/apis/repositories" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" - unsafe "unsafe" ) func init() { diff --git a/apis/stash/v1alpha1/types.go b/apis/stash/v1alpha1/types.go index 5c7638174..96da39a96 100644 --- a/apis/stash/v1alpha1/types.go +++ b/apis/stash/v1alpha1/types.go @@ -22,7 +22,7 @@ const ( type Restic struct { metav1.TypeMeta `json:",inline,omitempty"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ResticSpec `json:"spec,omitempty"` + Spec ResticSpec `json:"spec,omitempty"` } type ResticSpec struct { diff --git a/client/informers/externalversions/factory.go b/client/informers/externalversions/factory.go index 30771ee16..e2066ded2 100644 --- a/client/informers/externalversions/factory.go +++ b/client/informers/externalversions/factory.go @@ -19,6 +19,10 @@ limitations under the License. package externalversions import ( + reflect "reflect" + sync "sync" + time "time" + versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" stash "github.com/appscode/stash/client/informers/externalversions/stash" @@ -26,9 +30,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" - reflect "reflect" - sync "sync" - time "time" ) type sharedInformerFactory struct { diff --git a/client/informers/externalversions/generic.go b/client/informers/externalversions/generic.go index ff0a584c9..033ac0edc 100644 --- a/client/informers/externalversions/generic.go +++ b/client/informers/externalversions/generic.go @@ -20,6 +20,7 @@ package externalversions import ( "fmt" + v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" diff --git a/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/client/informers/externalversions/internalinterfaces/factory_interfaces.go index e96d6aeff..72b87b052 100644 --- a/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -19,11 +19,12 @@ limitations under the License. package internalinterfaces import ( + time "time" + versioned "github.com/appscode/stash/client/clientset/versioned" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" - time "time" ) type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer diff --git a/client/informers/externalversions/stash/v1alpha1/recovery.go b/client/informers/externalversions/stash/v1alpha1/recovery.go index 811fd108c..84d383df6 100644 --- a/client/informers/externalversions/stash/v1alpha1/recovery.go +++ b/client/informers/externalversions/stash/v1alpha1/recovery.go @@ -19,6 +19,8 @@ limitations under the License. package v1alpha1 import ( + time "time" + stash_v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" @@ -27,7 +29,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - time "time" ) // RecoveryInformer provides access to a shared informer and lister for diff --git a/client/informers/externalversions/stash/v1alpha1/repository.go b/client/informers/externalversions/stash/v1alpha1/repository.go index 57f1371fe..02d82ae99 100644 --- a/client/informers/externalversions/stash/v1alpha1/repository.go +++ b/client/informers/externalversions/stash/v1alpha1/repository.go @@ -19,6 +19,8 @@ limitations under the License. package v1alpha1 import ( + time "time" + stash_v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" @@ -27,7 +29,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - time "time" ) // RepositoryInformer provides access to a shared informer and lister for diff --git a/client/informers/externalversions/stash/v1alpha1/restic.go b/client/informers/externalversions/stash/v1alpha1/restic.go index 52c6fa535..a48cabe3d 100644 --- a/client/informers/externalversions/stash/v1alpha1/restic.go +++ b/client/informers/externalversions/stash/v1alpha1/restic.go @@ -19,6 +19,8 @@ limitations under the License. package v1alpha1 import ( + time "time" + stash_v1alpha1 "github.com/appscode/stash/apis/stash/v1alpha1" versioned "github.com/appscode/stash/client/clientset/versioned" internalinterfaces "github.com/appscode/stash/client/informers/externalversions/internalinterfaces" @@ -27,7 +29,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - time "time" ) // ResticInformer provides access to a shared informer and lister for diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index ac55f12b5..f6797ad30 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -227,7 +227,6 @@ func (c *Controller) setup() (*api.Restic, error) { if err = c.createRepositoryCrdIfNotExist(resource); err != nil { return resource, err } - return resource, nil } @@ -285,7 +284,11 @@ func (c *Controller) runResticBackup(resource *api.Restic) (err error) { restic_session_duration_seconds) } if err == nil { - stash_util.PatchRestic(c.stashClient.StashV1alpha1(), resource, func(in *api.Restic) *api.Restic { + repo, err := c.stashClient.StashV1alpha1().Repositories(resource.Namespace).Get(c.getRepositoryCrdName(resource), metav1.GetOptions{}) + if err != nil { + return + } + stash_util.PatchRepository(c.stashClient.StashV1alpha1(), repo, func(in *api.Repository) *api.Repository { in.Status.BackupCount++ in.Status.LastBackupTime = &startTime if in.Status.FirstBackupTime == nil { diff --git a/pkg/backup/repository.go b/pkg/backup/repository.go index 29ba999db..5635ca885 100644 --- a/pkg/backup/repository.go +++ b/pkg/backup/repository.go @@ -11,16 +11,9 @@ import ( func (c *Controller) createRepositoryCrdIfNotExist(restic *api.Restic) error { repository := &api.Repository{} - switch c.opt.Workload.Kind { - case api.KindDeployment, api.KindReplicaSet, api.KindReplicationController: - repository.Name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.Workload.Name - case api.KindStatefulSet: - repository.Name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.PodName - case api.KindDaemonSet: - repository.Name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.Workload.Name + "." + c.opt.NodeName - } - repository.Namespace = restic.Namespace + repository.Name = c.getRepositoryCrdName(restic) + _, err := c.stashClient.StashV1alpha1().Repositories(repository.Namespace).Get(repository.Name, metav1.GetOptions{}) if err != nil && kerr.IsNotFound(err) { repository.Labels = map[string]string{ @@ -49,3 +42,16 @@ func (c *Controller) createRepositoryCrdIfNotExist(restic *api.Restic) error { } return err } + +func (c *Controller) getRepositoryCrdName(restic *api.Restic) string { + name := "" + switch c.opt.Workload.Kind { + case api.KindDeployment, api.KindReplicaSet, api.KindReplicationController: + name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.Workload.Name + case api.KindStatefulSet: + name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.PodName + case api.KindDaemonSet: + name = strings.ToLower(c.opt.Workload.Kind) + "." + c.opt.Workload.Name + "." + c.opt.NodeName + } + return name +} From 2e257f9651e1a30db6ff2378bee0c80a9ca3af01 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Tue, 27 Mar 2018 14:59:03 +0600 Subject: [PATCH 07/11] DaemonSet --- test/e2e/daemonset_test.go | 99 +++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/test/e2e/daemonset_test.go b/test/e2e/daemonset_test.go index c2295bd18..07a448269 100644 --- a/test/e2e/daemonset_test.go +++ b/test/e2e/daemonset_test.go @@ -31,6 +31,7 @@ var _ = Describe("DaemonSet", func() { }) AfterEach(func() { time.Sleep(60 * time.Second) + f.DeleteRepositories() }) JustBeforeEach(func() { if missing, _ := BeZero().Match(cred); missing { @@ -59,10 +60,11 @@ var _ = Describe("DaemonSet", func() { By("Waiting for sidecar") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -84,10 +86,11 @@ var _ = Describe("DaemonSet", func() { By("Waiting for sidecar") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -109,10 +112,11 @@ var _ = Describe("DaemonSet", func() { By("Waiting for sidecar") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -136,10 +140,11 @@ var _ = Describe("DaemonSet", func() { By("Waiting for sidecar") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of DaemonSet " + daemon.Name) _, _, err = ext_util.PatchDaemonSet(f.KubeClient, &daemon, func(in *extensions.DaemonSet) *extensions.DaemonSet { @@ -150,6 +155,7 @@ var _ = Describe("DaemonSet", func() { }) Expect(err).NotTo(HaveOccurred()) + By("Waiting for sidecar to be removed") f.EventuallyDaemonSet(daemon.ObjectMeta).ShouldNot(HaveSidecar(util.StashContainer)) } @@ -169,10 +175,11 @@ var _ = Describe("DaemonSet", func() { By("Waiting for sidecar") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -185,6 +192,7 @@ var _ = Describe("DaemonSet", func() { }) Expect(err).NotTo(HaveOccurred()) + By("Waiting for sidecar to be removed") f.EventuallyDaemonSet(daemon.ObjectMeta).ShouldNot(HaveSidecar(util.StashContainer)) } @@ -200,6 +208,7 @@ var _ = Describe("DaemonSet", func() { err = f.CreateRecovery(recovery) Expect(err).NotTo(HaveOccurred()) + By("Waiting for Recovery to be succeed") f.EventuallyRecoverySucceed(recovery.ObjectMeta).Should(BeTrue()) } @@ -217,13 +226,14 @@ var _ = Describe("DaemonSet", func() { Expect(err).NotTo(HaveOccurred()) // sidecar should be added as soon as daemonset created, we don't need to wait for it - By("Checking sidecar created") + By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -276,10 +286,11 @@ var _ = Describe("DaemonSet", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of DaemonSet " + daemon.Name) obj, _, err = ext_util.PatchDaemonSet(f.KubeClient, &daemon, func(in *extensions.DaemonSet) *extensions.DaemonSet { @@ -324,10 +335,11 @@ var _ = Describe("DaemonSet", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } ) @@ -584,15 +596,14 @@ var _ = Describe("DaemonSet", func() { By("Waiting for init-container") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for initial backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, 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))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 2))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", 1))) @@ -627,10 +638,11 @@ var _ = Describe("DaemonSet", func() { By("Waiting for sidecar") f.EventuallyDaemonSet(daemon.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -642,18 +654,20 @@ var _ = Describe("DaemonSet", func() { }) Expect(err).NotTo(HaveOccurred()) - resticObj, err := f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err := f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) + Expect(repos.Items).NotTo(BeEmpty()) - previousBackupCount := resticObj.Status.BackupCount + previousBackupCount := repos.Items[0].Status.BackupCount By("Wating 2 minutes") time.Sleep(2 * time.Minute) By("Checking that Backup count has not changed") - resticObj, err = f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err = f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) - Expect(resticObj.Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) + Expect(repos.Items).NotTo(BeEmpty()) + Expect(repos.Items[0].Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) By(`Patching Restic with "paused: false"`) err = f.CreateOrPatchRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -663,9 +677,7 @@ var _ = Describe("DaemonSet", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -680,7 +692,6 @@ var _ = Describe("DaemonSet", func() { f.DeleteDaemonSet(daemon.ObjectMeta) f.DeleteRestic(restic.ObjectMeta) f.DeleteSecret(cred.ObjectMeta) - f.DeleteRepositories() }) BeforeEach(func() { cred = f.SecretForLocalBackend() @@ -706,9 +717,7 @@ var _ = Describe("DaemonSet", func() { f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDaemonSet, daemon.ObjectMeta, 1).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) From 62720e31ae39b0e78037f8f6a90a5160e6208895 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Tue, 27 Mar 2018 15:32:27 +0600 Subject: [PATCH 08/11] Deployment --- test/e2e/daemonset_test.go | 2 +- test/e2e/deployment_test.go | 114 +++++++++++++++++-------------- test/e2e/framework/repository.go | 12 ++++ 3 files changed, 76 insertions(+), 52 deletions(-) diff --git a/test/e2e/daemonset_test.go b/test/e2e/daemonset_test.go index 07a448269..b3aeb627f 100644 --- a/test/e2e/daemonset_test.go +++ b/test/e2e/daemonset_test.go @@ -30,8 +30,8 @@ var _ = Describe("DaemonSet", func() { f = root.Invoke() }) AfterEach(func() { - time.Sleep(60 * time.Second) f.DeleteRepositories() + time.Sleep(60 * time.Second) }) JustBeforeEach(func() { if missing, _ := BeZero().Match(cred); missing { diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index 93fee56ea..e1fa01f74 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -35,6 +35,7 @@ var _ = Describe("Deployment", func() { f = root.Invoke() }) AfterEach(func() { + f.DeleteRepositories() time.Sleep(60 * time.Second) }) JustBeforeEach(func() { @@ -64,10 +65,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -89,10 +91,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -114,10 +117,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -142,10 +146,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of Deployment " + deployment.Name) _, _, err = apps_util.PatchDeployment(f.KubeClient, &deployment, func(in *apps.Deployment) *apps.Deployment { @@ -175,10 +180,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -226,12 +232,14 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for leader election") f.CheckLeaderElection(deployment.ObjectMeta, api.KindDeployment) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -254,10 +262,11 @@ var _ = Describe("Deployment", func() { By("Checking sidecar created") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -310,10 +319,11 @@ var _ = Describe("Deployment", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of Deployment " + deployment.Name) obj, _, err = apps_util.PatchDeployment(f.KubeClient, &deployment, func(in *apps.Deployment) *apps.Deployment { @@ -358,10 +368,11 @@ var _ = Describe("Deployment", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } shouldDeleteJobAndDependents = func(jobName, namespace string) { @@ -718,10 +729,11 @@ var _ = Describe("Deployment", func() { By("Waiting for init-container") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -768,10 +780,11 @@ var _ = Describe("Deployment", func() { By("Waiting for init-container") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -833,10 +846,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -936,10 +950,11 @@ var _ = Describe("Deployment", func() { By("Waiting for sidecar") f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Wating for Repository CRD") + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -951,18 +966,20 @@ var _ = Describe("Deployment", func() { }) Expect(err).NotTo(HaveOccurred()) - resticObj, err := f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err := f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) + Expect(repos.Items).NotTo(BeEmpty()) - previousBackupCount := resticObj.Status.BackupCount + previousBackupCount := repos.Items[0].Status.BackupCount By("Wating 2 minutes") time.Sleep(2 * time.Minute) By("Checking that Backup count has not changed") - resticObj, err = f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err = f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) - Expect(resticObj.Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) + Expect(repos.Items).NotTo(BeEmpty()) + Expect(repos.Items[0].Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) By(`Patching Restic with "paused: false"`) err = f.CreateOrPatchRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -972,9 +989,7 @@ var _ = Describe("Deployment", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -990,7 +1005,6 @@ var _ = Describe("Deployment", func() { f.DeleteDeployment(deployment.ObjectMeta) f.DeleteRestic(restic.ObjectMeta) f.DeleteSecret(cred.ObjectMeta) - f.DeleteRepositories() }) BeforeEach(func() { cred = f.SecretForLocalBackend() @@ -1013,12 +1027,10 @@ var _ = Describe("Deployment", func() { f.EventuallyDeployment(deployment.ObjectMeta).Should(HaveSidecar(util.StashContainer)) By("Wating for Repository CRD") - f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, 1).ShouldNot(BeEmpty()) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) diff --git a/test/e2e/framework/repository.go b/test/e2e/framework/repository.go index 358e91203..eca365340 100644 --- a/test/e2e/framework/repository.go +++ b/test/e2e/framework/repository.go @@ -49,3 +49,15 @@ func (f *Framework) DeleteRepositories() { f.StashClient.StashV1alpha1().Repositories(repo.Namespace).Delete(repo.Name, deleteInBackground()) } } + +func (f *Framework) BackupCountInRepositoriesStatus(repos []*api.Repository) int64 { + backupCount := int64(99999) + + //use minimum backupCount among all repos + for _, repo := range repos { + if backupCount > repo.Status.BackupCount { + backupCount = repo.Status.BackupCount + } + } + return backupCount +} From 5e66a1feb3c6cf19952347bea27efbac3623bb61 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Tue, 27 Mar 2018 15:37:58 +0600 Subject: [PATCH 09/11] ReplicationController --- test/e2e/rc_test.go | 106 ++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/test/e2e/rc_test.go b/test/e2e/rc_test.go index c4ec0b4d8..ae4a70c97 100644 --- a/test/e2e/rc_test.go +++ b/test/e2e/rc_test.go @@ -30,6 +30,7 @@ var _ = Describe("ReplicationController", func() { f = root.Invoke() }) AfterEach(func() { + f.DeleteRepositories() time.Sleep(60 * time.Second) }) JustBeforeEach(func() { @@ -59,10 +60,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -84,10 +86,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -109,10 +112,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -137,10 +141,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicationController " + rc.Name) _, _, err = core_util.PatchRC(f.KubeClient, &rc, func(in *core.ReplicationController) *core.ReplicationController { @@ -170,10 +175,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -222,10 +228,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -248,10 +255,11 @@ var _ = Describe("ReplicationController", func() { By("Checking sidecar created") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -304,10 +312,11 @@ var _ = Describe("ReplicationController", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicationController " + rc.Name) obj, _, err = core_util.PatchRC(f.KubeClient, &rc, func(in *core.ReplicationController) *core.ReplicationController { @@ -352,10 +361,11 @@ var _ = Describe("ReplicationController", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } ) @@ -635,10 +645,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for init-container") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -685,10 +696,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for init-container") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -726,10 +738,11 @@ var _ = Describe("ReplicationController", func() { By("Waiting for sidecar") f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -741,18 +754,20 @@ var _ = Describe("ReplicationController", func() { }) Expect(err).NotTo(HaveOccurred()) - resticObj, err := f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err := f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) + Expect(repos.Items).NotTo(BeEmpty()) - previousBackupCount := resticObj.Status.BackupCount + previousBackupCount := repos.Items[0].Status.BackupCount By("Wating 2 minutes") time.Sleep(2 * time.Minute) By("Checking that Backup count has not changed") - resticObj, err = f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err = f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) - Expect(resticObj.Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) + Expect(repos.Items).NotTo(BeEmpty()) + Expect(repos.Items[0].Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) By(`Patching Restic with "paused: false"`) err = f.CreateOrPatchRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -762,9 +777,7 @@ var _ = Describe("ReplicationController", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -780,7 +793,6 @@ var _ = Describe("ReplicationController", func() { f.DeleteReplicationController(rc.ObjectMeta) f.DeleteRestic(restic.ObjectMeta) f.DeleteSecret(cred.ObjectMeta) - f.DeleteRepositories() }) BeforeEach(func() { cred = f.SecretForLocalBackend() @@ -803,12 +815,10 @@ var _ = Describe("ReplicationController", func() { f.EventuallyReplicationController(rc.ObjectMeta).Should(HaveSidecar(util.StashContainer)) By("Waiting for Repository CRD") - f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, 1).ShouldNot(BeEmpty()) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) From 2ce8ac4ae79a631959590a0140cfd4e40d7853b1 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Tue, 27 Mar 2018 15:44:15 +0600 Subject: [PATCH 10/11] ReplicaSet --- test/e2e/replicaset_test.go | 107 ++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/test/e2e/replicaset_test.go b/test/e2e/replicaset_test.go index 37ada7368..7fdb32689 100644 --- a/test/e2e/replicaset_test.go +++ b/test/e2e/replicaset_test.go @@ -31,6 +31,7 @@ var _ = Describe("ReplicaSet", func() { f = root.Invoke() }) AfterEach(func() { + f.DeleteRepositories() time.Sleep(60 * time.Second) }) JustBeforeEach(func() { @@ -60,10 +61,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -85,10 +87,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -110,10 +113,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -137,10 +141,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicaSet " + rs.Name) _, _, err = ext_util.PatchReplicaSet(f.KubeClient, &rs, func(in *extensions.ReplicaSet) *extensions.ReplicaSet { @@ -170,10 +175,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -220,12 +226,14 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for leader election") f.CheckLeaderElection(rs.ObjectMeta, api.KindReplicaSet) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -248,10 +256,11 @@ var _ = Describe("ReplicaSet", func() { By("Checking sidecar created") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -304,10 +313,11 @@ var _ = Describe("ReplicaSet", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicaSet " + rs.Name) obj, _, err = ext_util.PatchReplicaSet(f.KubeClient, &rs, func(in *extensions.ReplicaSet) *extensions.ReplicaSet { @@ -352,10 +362,11 @@ var _ = Describe("ReplicaSet", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } ) @@ -634,10 +645,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for init-container") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -684,10 +696,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for init-container") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -725,10 +738,11 @@ var _ = Describe("ReplicaSet", func() { By("Waiting for sidecar") f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -740,18 +754,20 @@ var _ = Describe("ReplicaSet", func() { }) Expect(err).NotTo(HaveOccurred()) - resticObj, err := f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err := f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) + Expect(repos.Items).NotTo(BeEmpty()) - previousBackupCount := resticObj.Status.BackupCount + previousBackupCount := repos.Items[0].Status.BackupCount By("Wating 2 minutes") time.Sleep(2 * time.Minute) By("Checking that Backup count has not changed") - resticObj, err = f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err = f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) - Expect(resticObj.Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) + Expect(repos.Items).NotTo(BeEmpty()) + Expect(repos.Items[0].Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) By(`Patching Restic with "paused: false"`) err = f.CreateOrPatchRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -761,9 +777,7 @@ var _ = Describe("ReplicaSet", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -778,7 +792,6 @@ var _ = Describe("ReplicaSet", func() { f.DeleteReplicaSet(rs.ObjectMeta) f.DeleteRestic(restic.ObjectMeta) f.DeleteSecret(cred.ObjectMeta) - f.DeleteRepositories() }) BeforeEach(func() { cred = f.SecretForLocalBackend() @@ -801,12 +814,10 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyReplicaSet(rs.ObjectMeta).Should(HaveSidecar(util.StashContainer)) By("Waiting for Repository CRD") - f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, 1).ShouldNot(BeEmpty()) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) From 73c01ff1f599b9f3403b9146c64bb47d1d5f9e10 Mon Sep 17 00:00:00 2001 From: emruz-hossain Date: Tue, 27 Mar 2018 15:48:32 +0600 Subject: [PATCH 11/11] StatefulSet --- test/e2e/deployment_test.go | 30 ++++----- test/e2e/rc_test.go | 28 ++++---- test/e2e/replicaset_test.go | 28 ++++---- test/e2e/statefulset_test.go | 122 +++++++++++++++++++++-------------- 4 files changed, 117 insertions(+), 91 deletions(-) diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index e1fa01f74..b4b7786bf 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -69,7 +69,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -95,7 +95,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -121,7 +121,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -150,7 +150,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of Deployment " + deployment.Name) _, _, err = apps_util.PatchDeployment(f.KubeClient, &deployment, func(in *apps.Deployment) *apps.Deployment { @@ -184,7 +184,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -239,7 +239,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -266,7 +266,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -323,7 +323,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of Deployment " + deployment.Name) obj, _, err = apps_util.PatchDeployment(f.KubeClient, &deployment, func(in *apps.Deployment) *apps.Deployment { @@ -372,7 +372,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } shouldDeleteJobAndDependents = func(jobName, namespace string) { @@ -733,7 +733,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -784,7 +784,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -850,7 +850,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -954,7 +954,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -989,7 +989,7 @@ var _ = Describe("Deployment", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -1030,7 +1030,7 @@ var _ = Describe("Deployment", func() { f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindDeployment,deployment.ObjectMeta,int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindDeployment, deployment.ObjectMeta, int(*deployment.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) diff --git a/test/e2e/rc_test.go b/test/e2e/rc_test.go index ae4a70c97..d13939bd4 100644 --- a/test/e2e/rc_test.go +++ b/test/e2e/rc_test.go @@ -64,7 +64,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -90,7 +90,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -116,7 +116,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -145,7 +145,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicationController " + rc.Name) _, _, err = core_util.PatchRC(f.KubeClient, &rc, func(in *core.ReplicationController) *core.ReplicationController { @@ -179,7 +179,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -232,7 +232,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -259,7 +259,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -316,7 +316,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicationController " + rc.Name) obj, _, err = core_util.PatchRC(f.KubeClient, &rc, func(in *core.ReplicationController) *core.ReplicationController { @@ -365,7 +365,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } ) @@ -649,7 +649,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -700,7 +700,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -742,7 +742,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -777,7 +777,7 @@ var _ = Describe("ReplicationController", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -818,7 +818,7 @@ var _ = Describe("ReplicationController", func() { f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicationController,rc.ObjectMeta,int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicationController, rc.ObjectMeta, int(*rc.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) 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 7fdb32689..036815671 100644 --- a/test/e2e/replicaset_test.go +++ b/test/e2e/replicaset_test.go @@ -65,7 +65,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -91,7 +91,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -117,7 +117,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -145,7 +145,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicaSet " + rs.Name) _, _, err = ext_util.PatchReplicaSet(f.KubeClient, &rs, func(in *extensions.ReplicaSet) *extensions.ReplicaSet { @@ -179,7 +179,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -233,7 +233,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -260,7 +260,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -317,7 +317,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of ReplicaSet " + rs.Name) obj, _, err = ext_util.PatchReplicaSet(f.KubeClient, &rs, func(in *extensions.ReplicaSet) *extensions.ReplicaSet { @@ -366,7 +366,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } ) @@ -649,7 +649,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -700,7 +700,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -742,7 +742,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -777,7 +777,7 @@ var _ = Describe("ReplicaSet", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -817,7 +817,7 @@ var _ = Describe("ReplicaSet", func() { f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).ShouldNot(BeEmpty()) By("Waiting for backup to complete") - f.EventuallyRepository(api.KindReplicaSet,rs.ObjectMeta,int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindReplicaSet, rs.ObjectMeta, int(*rs.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) 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 760c51c98..548fdd150 100644 --- a/test/e2e/statefulset_test.go +++ b/test/e2e/statefulset_test.go @@ -32,6 +32,7 @@ var _ = Describe("StatefulSet", func() { f = root.Invoke() }) AfterEach(func() { + f.DeleteRepositories() time.Sleep(60 * time.Second) }) JustBeforeEach(func() { @@ -66,10 +67,13 @@ var _ = Describe("StatefulSet", func() { By("Waiting for sidecar") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -95,10 +99,13 @@ var _ = Describe("StatefulSet", func() { By("Waiting for sidecar") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -124,10 +131,13 @@ var _ = Describe("StatefulSet", func() { By("Waiting for sidecar") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Deleting restic " + restic.Name) f.DeleteRestic(restic.ObjectMeta) @@ -156,10 +166,13 @@ var _ = Describe("StatefulSet", func() { By("Waiting for sidecar") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of StatefulSet " + ss.Name) _, _, err = apps_util.PatchStatefulSet(f.KubeClient, &ss, func(in *apps.StatefulSet) *apps.StatefulSet { @@ -194,10 +207,13 @@ var _ = Describe("StatefulSet", func() { By("Waiting for sidecar") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Change selector of Restic " + restic.Name) err = f.UpdateRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -249,10 +265,13 @@ var _ = Describe("StatefulSet", func() { By("Checking sidecar created") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -317,10 +336,13 @@ var _ = Describe("StatefulSet", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Removing labels of StatefulSet " + ss.Name) obj, _, err = apps_util.PatchStatefulSet(f.KubeClient, &ss, func(in *apps.StatefulSet) *apps.StatefulSet { @@ -369,10 +391,13 @@ var _ = Describe("StatefulSet", func() { By("Checking sidecar added") Expect(obj).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) } ) @@ -641,15 +666,16 @@ var _ = Describe("StatefulSet", func() { By("Waiting for init-container") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveInitContainer(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for initial backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, 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))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 2))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", 1))) @@ -689,10 +715,13 @@ var _ = Describe("StatefulSet", func() { By("Waiting for sidecar") f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) + By("Waiting for Repository CRD") + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) + By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -704,18 +733,20 @@ var _ = Describe("StatefulSet", func() { }) Expect(err).NotTo(HaveOccurred()) - resticObj, err := f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err := f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) + Expect(repos.Items).NotTo(BeEmpty()) - previousBackupCount := resticObj.Status.BackupCount + previousBackupCount := repos.Items[0].Status.BackupCount By("Wating 2 minutes") time.Sleep(2 * time.Minute) By("Checking that Backup count has not changed") - resticObj, err = f.StashClient.StashV1alpha1().Restics(restic.Namespace).Get(restic.Name, metav1.GetOptions{}) + repos, err = f.StashClient.StashV1alpha1().Repositories(restic.Namespace).List(metav1.ListOptions{}) Expect(err).NotTo(HaveOccurred()) - Expect(resticObj.Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) + Expect(repos.Items).NotTo(BeEmpty()) + Expect(repos.Items[0].Status.BackupCount).Should(BeNumerically("==", previousBackupCount)) By(`Patching Restic with "paused: false"`) err = f.CreateOrPatchRestic(restic.ObjectMeta, func(in *api.Restic) *api.Restic { @@ -725,9 +756,7 @@ var _ = Describe("StatefulSet", func() { Expect(err).NotTo(HaveOccurred()) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">", previousBackupCount))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">", previousBackupCount))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">", previousBackupCount))) @@ -769,12 +798,12 @@ var _ = Describe("StatefulSet", func() { f.EventuallyStatefulSet(ss.ObjectMeta).Should(HaveSidecar(util.StashContainer)) By("Waiting for Repository CRD") - f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, 1).ShouldNot(BeEmpty()) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(func(repoList []*api.Repository) int { + return len(repoList) + }, BeNumerically("==", int(*ss.Spec.Replicas)))) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1))) @@ -787,7 +816,6 @@ var _ = Describe("StatefulSet", func() { f.DeleteService(svc.ObjectMeta) f.DeleteRestic(restic.ObjectMeta) f.DeleteSecret(cred.ObjectMeta) - f.DeleteRepositories() }) BeforeEach(func() { cred = f.SecretForLocalBackend() @@ -820,9 +848,7 @@ var _ = Describe("StatefulSet", func() { }, BeNumerically("==", int(*ss.Spec.Replicas)))) By("Waiting for backup to complete") - f.EventuallyRestic(restic.ObjectMeta).Should(WithTransform(func(r *api.Restic) int64 { - return r.Status.BackupCount - }, BeNumerically(">=", 1))) + f.EventuallyRepository(api.KindStatefulSet, ss.ObjectMeta, int(*ss.Spec.Replicas)).Should(WithTransform(f.BackupCountInRepositoriesStatus, BeNumerically(">=", 1))) By("Waiting for backup event") f.EventualEvent(restic.ObjectMeta).Should(WithTransform(f.CountSuccessfulBackups, BeNumerically(">=", 1)))