diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 126d721ed..29fba15ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,4 +123,4 @@ jobs: make install echo sleep 10 - make e2e-tests + make e2e-parallel diff --git a/test/e2e/framework/daemonset.go b/test/e2e/framework/daemonset.go index c81338551..bcd7506c9 100644 --- a/test/e2e/framework/daemonset.go +++ b/test/e2e/framework/daemonset.go @@ -27,13 +27,11 @@ import ( . "github.com/onsi/gomega" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" - kerr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/wait" kutil "kmodules.xyz/client-go" apps_util "kmodules.xyz/client-go/apps/v1" - meta_util "kmodules.xyz/client-go/meta" ) func (fi *Invocation) DaemonSet(name, volumeName string) apps.DaemonSet { @@ -98,14 +96,6 @@ func (f *Framework) CreateDaemonSet(obj apps.DaemonSet) (*apps.DaemonSet, error) return f.KubeClient.AppsV1().DaemonSets(obj.Namespace).Create(context.TODO(), &obj, metav1.CreateOptions{}) } -func (f *Framework) DeleteDaemonSet(meta metav1.ObjectMeta) error { - err := f.KubeClient.AppsV1().DaemonSets(meta.Namespace).Delete(context.TODO(), meta.Name, meta_util.DeleteInBackground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - func (f *Framework) EventuallyDaemonSet(meta metav1.ObjectMeta) GomegaAsyncAssertion { return Eventually(func() *apps.DaemonSet { obj, err := f.KubeClient.AppsV1().DaemonSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) @@ -142,34 +132,6 @@ func (fi *Invocation) WaitUntilDaemonSetReadyWithSidecar(meta metav1.ObjectMeta) }) } -func (fi *Invocation) WaitUntilDaemonSetReadyWithInitContainer(meta metav1.ObjectMeta) error { - return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { - if obj, err := fi.KubeClient.AppsV1().DaemonSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err == nil { - if obj.Status.DesiredNumberScheduled == obj.Status.NumberReady { - pods, err := fi.GetAllPods(obj.ObjectMeta) - if err != nil { - return false, err - } - - for i := range pods { - hasInitContainer := false - for _, c := range pods[i].Spec.InitContainers { - if c.Name == apis.StashInitContainer { - hasInitContainer = true - } - } - if !hasInitContainer { - return false, nil - } - } - return true, nil - } - return false, nil - } - return false, nil - }) -} - func (fi *Invocation) DeployDaemonSet(name string, volumeName string) (*apps.DaemonSet, error) { // Generate DaemonSet definition dmn := fi.DaemonSet(name, volumeName) diff --git a/test/e2e/framework/deployment.go b/test/e2e/framework/deployment.go index 58cdaa811..3d6b1e8b3 100644 --- a/test/e2e/framework/deployment.go +++ b/test/e2e/framework/deployment.go @@ -33,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" kutil "kmodules.xyz/client-go" apps_util "kmodules.xyz/client-go/apps/v1" - meta_util "kmodules.xyz/client-go/meta" ) const ( @@ -72,14 +71,6 @@ func (f *Framework) CreateDeployment(obj apps.Deployment) (*apps.Deployment, err return f.KubeClient.AppsV1().Deployments(obj.Namespace).Create(context.TODO(), &obj, metav1.CreateOptions{}) } -func (f *Framework) DeleteDeployment(meta metav1.ObjectMeta) error { - err := f.KubeClient.AppsV1().Deployments(meta.Namespace).Delete(context.TODO(), meta.Name, meta_util.DeleteInBackground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - func (f *Framework) EventuallyDeployment(meta metav1.ObjectMeta) GomegaAsyncAssertion { return Eventually(func() *apps.Deployment { obj, err := f.KubeClient.AppsV1().Deployments(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) @@ -119,34 +110,6 @@ func (fi *Invocation) WaitUntilDeploymentReadyWithSidecar(meta metav1.ObjectMeta }) } -func (fi *Invocation) WaitUntilDeploymentReadyWithInitContainer(meta metav1.ObjectMeta) error { - return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { - if obj, err := fi.KubeClient.AppsV1().Deployments(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err == nil { - if obj.Status.Replicas == obj.Status.ReadyReplicas { - pods, err := fi.GetAllPods(obj.ObjectMeta) - if err != nil { - return false, err - } - - for i := range pods { - hasInitContainer := false - for _, c := range pods[i].Spec.InitContainers { - if c.Name == apis.StashInitContainer { - hasInitContainer = true - } - } - if !hasInitContainer { - return false, nil - } - } - return true, nil - } - return false, nil - } - return false, nil - }) -} - func (fi *Invocation) DeployDeployment(name string, replica int32, volName string, transformFuncs ...func(dp *apps.Deployment)) (*apps.Deployment, error) { // append test case specific suffix so that name does not conflict during parallel test pvcName := fmt.Sprintf("%s-%s", volName, fi.app) diff --git a/test/e2e/framework/minio_server.go b/test/e2e/framework/minio_server.go index c4656a63f..37a1cf640 100644 --- a/test/e2e/framework/minio_server.go +++ b/test/e2e/framework/minio_server.go @@ -22,6 +22,8 @@ import ( "net" "path/filepath" + "stash.appscode.dev/apimachinery/apis" + "github.com/appscode/go/types" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -69,23 +71,24 @@ func (f *Framework) CreateMinioServer(tls bool, ips []net.IP) (string, error) { return "", err } + //creating pvc for minio server + mpvc = f.PVCForMinioServer() + err = f.CreatePersistentVolumeClaimForMinioServer(mpvc) + if err != nil { + return "", nil + } + //creating deployment for minio server - mdeploy = f.DeploymentForMinioServer() + mdeploy = f.DeploymentForMinioServer(mpvc, mcred) if !tls { // if tls not enabled then don't mount secret for cacerts - mdeploy.Spec.Template.Spec.Containers = f.RemoveSecretVolumeMount(mdeploy.Spec.Template.Spec.Containers) + mdeploy.Spec.Template.Spec.Containers = f.RemoveSecretVolumeMount(mdeploy.Spec.Template.Spec.Containers, mcred) } + err = f.CreateDeploymentForMinioServer(mdeploy) if err != nil { return "", err } - //creating pvc for minio server - mpvc = f.PVCForMinioServer() - err = f.CreatePersistentVolumeClaimForMinioServer(mpvc) - if err != nil { - return "", nil - } - //creating service for minio server msrvc = f.ServiceForMinioServer() _, err = f.CreateServiceForMinioServer(msrvc) @@ -118,11 +121,11 @@ func (f *Framework) SecretForMinioServer(ips []net.IP) core.Secret { func (f *Framework) PVCForMinioServer() core.PersistentVolumeClaim { return core.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf(MinioPVCStorage+"%s", f.namespace), + Name: fmt.Sprintf("%s-%s", MinioPVCStorage, f.namespace), Namespace: f.namespace, Labels: map[string]string{ // this label will be used to mount this pvc as volume in minio server container - "app": "minio-storage-claim", + apis.LabelApp: fmt.Sprintf("%s-%s", MinioServer, f.namespace), }, }, Spec: core.PersistentVolumeClaimSpec{ @@ -131,7 +134,7 @@ func (f *Framework) PVCForMinioServer() core.PersistentVolumeClaim { }, Resources: core.ResourceRequirements{ Requests: core.ResourceList{ - core.ResourceName(core.ResourceStorage): resource.MustParse("2Gi"), + core.ResourceStorage: resource.MustParse("1Gi"), }, }, StorageClassName: types.StringP(StandardStorageClass), @@ -144,9 +147,9 @@ func (f *Framework) CreatePersistentVolumeClaimForMinioServer(obj core.Persisten return err } -func (f *Framework) DeploymentForMinioServer() apps.Deployment { +func (f *Framework) DeploymentForMinioServer(pvc core.PersistentVolumeClaim, secret core.Secret) apps.Deployment { labels := map[string]string{ - "app": f.namespace + "minio-server", + apis.LabelApp: fmt.Sprintf("%s-%s", MinioServer, f.namespace), } return apps.Deployment{ @@ -174,7 +177,7 @@ func (f *Framework) DeploymentForMinioServer() apps.Deployment { Name: "minio-storage", VolumeSource: core.VolumeSource{ PersistentVolumeClaim: &core.PersistentVolumeClaimVolumeSource{ - ClaimName: fmt.Sprintf(MinioPVCStorage+"%s", f.namespace), + ClaimName: pvc.Name, }, }, }, @@ -182,7 +185,7 @@ func (f *Framework) DeploymentForMinioServer() apps.Deployment { Name: "minio-certs", VolumeSource: core.VolumeSource{ Secret: &core.SecretVolumeSource{ - SecretName: fmt.Sprintf(MinioServerSecret+"%s", f.namespace), + SecretName: secret.Name, Items: []core.KeyToPath{ { Key: MINIO_PUBLIC_CRT_NAME, @@ -225,7 +228,6 @@ func (f *Framework) DeploymentForMinioServer() apps.Deployment { Ports: []core.ContainerPort{ { ContainerPort: int32(443), - HostPort: int32(443), }, }, VolumeMounts: []core.VolumeMount{ @@ -246,11 +248,11 @@ func (f *Framework) DeploymentForMinioServer() apps.Deployment { } } -func (f *Framework) RemoveSecretVolumeMount(containers []core.Container) []core.Container { +func (f *Framework) RemoveSecretVolumeMount(containers []core.Container, secret core.Secret) []core.Container { resp := make([]core.Container, 0) for _, c := range containers { if c.Name == "minio-server" { - c.VolumeMounts = core_util.EnsureVolumeMountDeleted(c.VolumeMounts, "minio-secret") + c.VolumeMounts = core_util.EnsureVolumeMountDeleted(c.VolumeMounts, secret.Name) } resp = append(resp, c) } @@ -277,7 +279,7 @@ func (f *Framework) ServiceForMinioServer() core.Service { }, }, Selector: map[string]string{ - "app": f.namespace + "minio-server", + apis.LabelApp: fmt.Sprintf("%s-%s", MinioServer, f.namespace), }, }, } diff --git a/test/e2e/framework/pod.go b/test/e2e/framework/pod.go index 248c294af..3eae3f0ea 100644 --- a/test/e2e/framework/pod.go +++ b/test/e2e/framework/pod.go @@ -38,7 +38,6 @@ const ( TestSourceDataMountPath = "/source/data" TestSafeDataMountPath = "/safe/data" OperatorNamespace = "kube-system" - OperatorName = "stash-operator" ) func (fi *Invocation) PodTemplate(labels map[string]string, pvcName, volName string) core.PodTemplateSpec { diff --git a/test/e2e/framework/pvc.go b/test/e2e/framework/pvc.go index 76220c197..e8e1dfea6 100644 --- a/test/e2e/framework/pvc.go +++ b/test/e2e/framework/pvc.go @@ -29,7 +29,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" core "k8s.io/api/core/v1" - kerr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" meta_util "kmodules.xyz/client-go/meta" @@ -59,14 +58,6 @@ func (f *Framework) CreatePersistentVolumeClaim(pvc *core.PersistentVolumeClaim) return f.KubeClient.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{}) } -func (fi *Invocation) DeletePersistentVolumeClaim(meta metav1.ObjectMeta) error { - err := fi.KubeClient.CoreV1().PersistentVolumeClaims(meta.Namespace).Delete(context.TODO(), meta.Name, *deleteInForeground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - func (fi *Invocation) CreateNewPVC(name string) (*core.PersistentVolumeClaim, error) { // Generate PVC definition pvc := fi.PersistentVolumeClaim(name) diff --git a/test/e2e/framework/replicaset.go b/test/e2e/framework/replicaset.go index 8536dac43..416722388 100644 --- a/test/e2e/framework/replicaset.go +++ b/test/e2e/framework/replicaset.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" kutil "kmodules.xyz/client-go" apps_util "kmodules.xyz/client-go/apps/v1" - meta_util "kmodules.xyz/client-go/meta" ) func (fi *Invocation) ReplicaSet(name, pvcName, volName string) apps.ReplicaSet { @@ -61,14 +60,6 @@ func (f *Framework) CreateReplicaSet(obj apps.ReplicaSet) (*apps.ReplicaSet, err return f.KubeClient.AppsV1().ReplicaSets(obj.Namespace).Create(context.TODO(), &obj, metav1.CreateOptions{}) } -func (f *Framework) DeleteReplicaSet(meta metav1.ObjectMeta) error { - err := f.KubeClient.AppsV1().ReplicaSets(meta.Namespace).Delete(context.TODO(), meta.Name, meta_util.DeleteInBackground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - func (f *Framework) EventuallyReplicaSet(meta metav1.ObjectMeta) GomegaAsyncAssertion { return Eventually(func() *apps.ReplicaSet { obj, err := f.KubeClient.AppsV1().ReplicaSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) @@ -105,34 +96,6 @@ func (fi *Invocation) WaitUntilRSReadyWithSidecar(meta metav1.ObjectMeta) error }) } -func (fi *Invocation) WaitUntilRSReadyWithInitContainer(meta metav1.ObjectMeta) error { - return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { - if obj, err := fi.KubeClient.AppsV1().ReplicaSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err == nil { - if obj.Status.Replicas == obj.Status.ReadyReplicas { - pods, err := fi.GetAllPods(obj.ObjectMeta) - if err != nil { - return false, err - } - - for i := range pods { - hasInitContainer := false - for _, c := range pods[i].Spec.InitContainers { - if c.Name == apis.StashInitContainer { - hasInitContainer = true - } - } - if !hasInitContainer { - return false, nil - } - } - return true, nil - } - return false, nil - } - return false, nil - }) -} - func (fi *Invocation) DeployReplicaSet(name string, replica int32, volName string) (*apps.ReplicaSet, error) { // append test case specific suffix so that name does not conflict during parallel test pvcName := fmt.Sprintf("%s-%s", volName, fi.app) diff --git a/test/e2e/framework/replicationcontroller.go b/test/e2e/framework/replicationcontroller.go index 36ea10ab4..fd0433313 100644 --- a/test/e2e/framework/replicationcontroller.go +++ b/test/e2e/framework/replicationcontroller.go @@ -32,7 +32,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" kutil "kmodules.xyz/client-go" - meta_util "kmodules.xyz/client-go/meta" ) func (fi *Invocation) ReplicationController(name, pvcName, volName string) core.ReplicationController { @@ -59,14 +58,6 @@ func (f *Framework) CreateReplicationController(obj core.ReplicationController) return f.KubeClient.CoreV1().ReplicationControllers(obj.Namespace).Create(context.TODO(), &obj, metav1.CreateOptions{}) } -func (f *Framework) DeleteReplicationController(meta metav1.ObjectMeta) error { - err := f.KubeClient.CoreV1().ReplicationControllers(meta.Namespace).Delete(context.TODO(), meta.Name, meta_util.DeleteInBackground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - func (f *Framework) EventuallyReplicationController(meta metav1.ObjectMeta) GomegaAsyncAssertion { return Eventually(func() *core.ReplicationController { obj, err := f.KubeClient.CoreV1().ReplicationControllers(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) @@ -103,34 +94,6 @@ func (fi *Invocation) WaitUntilRCReadyWithSidecar(meta metav1.ObjectMeta) error }) } -func (fi *Invocation) WaitUntilRCReadyWithInitContainer(meta metav1.ObjectMeta) error { - return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { - if obj, err := fi.KubeClient.CoreV1().ReplicationControllers(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err == nil { - if obj.Status.Replicas == obj.Status.ReadyReplicas { - pods, err := fi.GetAllPods(obj.ObjectMeta) - if err != nil { - return false, err - } - - for i := range pods { - hasInitContainer := false - for _, c := range pods[i].Spec.InitContainers { - if c.Name == apis.StashInitContainer { - hasInitContainer = true - } - } - if !hasInitContainer { - return false, nil - } - } - return true, nil - } - return false, nil - } - return false, nil - }) -} - func (fi *Invocation) DeployReplicationController(name string, replica int32, volName string) (*core.ReplicationController, error) { // append test case specific suffix so that name does not conflict during parallel test pvcName := fmt.Sprintf("%s-%s", volName, fi.app) diff --git a/test/e2e/framework/repository.go b/test/e2e/framework/repository.go index 15e756982..efaec2ce7 100644 --- a/test/e2e/framework/repository.go +++ b/test/e2e/framework/repository.go @@ -19,7 +19,6 @@ package framework import ( "context" "fmt" - "math" "strconv" "time" @@ -31,11 +30,9 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "gomodules.xyz/stow" - apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" kerr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - meta_util "kmodules.xyz/client-go/meta" pfutil "kmodules.xyz/client-go/tools/portforward" store "kmodules.xyz/objectstore-api/api/v1" "kmodules.xyz/objectstore-api/osm" @@ -47,25 +44,6 @@ type KindMetaReplicas struct { Replicas int } -func (f *Framework) EventuallyRepository(workload interface{}) GomegaAsyncAssertion { - return Eventually(func() []*api.Repository { - switch w := workload.(type) { - case *apps.DaemonSet: - return f.DaemonSetRepos(w) - case *apps.Deployment: - return f.DeploymentRepos(w) - case *core.ReplicationController: - return f.ReplicationControllerRepos(w) - case *apps.ReplicaSet: - return f.ReplicaSetRepos(w) - case *apps.StatefulSet: - return f.StatefulSetRepos(w) - default: - return nil - } - }) -} - func (f *Framework) EventuallyRepositoryCreated(meta metav1.ObjectMeta) GomegaAsyncAssertion { return Eventually(func() bool { _, err := f.StashClient.StashV1alpha1().Repositories(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) @@ -101,13 +79,6 @@ func (f *Framework) GetRepositories(kmr KindMetaReplicas) []*api.Repository { return repositories } -func (f *Framework) DeleteRepositories(repositories []*api.Repository) { - for _, repo := range repositories { - err := f.StashClient.StashV1alpha1().Repositories(repo.Namespace).Delete(context.TODO(), repo.Name, meta_util.DeleteInBackground()) - Expect(err).NotTo(HaveOccurred()) - } -} - func (f *Framework) DeleteRepository(repository *api.Repository) error { err := f.StashClient.StashV1alpha1().Repositories(repository.Namespace).Delete(context.TODO(), repository.Name, metav1.DeleteOptions{}) if err != nil && !kerr.IsNotFound(err) { @@ -171,25 +142,6 @@ func (f *Framework) BrowseMinioRepository(repo *api.Repository) ([]stow.Item, er return f.BrowseBackendRepository(repo) } -func (f *Framework) BackupCountInRepositoriesStatus(repos []*api.Repository) int64 { - var backupCount int64 = math.MaxInt64 - - // use minimum backupCount among all repos - for _, repo := range repos { - if int64(repo.Status.BackupCount) < backupCount { - backupCount = int64(repo.Status.BackupCount) - } - } - return backupCount -} - -func (f *Framework) CreateRepository(repo *api.Repository) error { - _, err := f.StashClient.StashV1alpha1().Repositories(repo.Namespace).Create(context.TODO(), repo, metav1.CreateOptions{}) - - return err - -} - func (fi *Invocation) NewLocalRepositoryWithPVC(secretName string, pvcName string) *api.Repository { return &api.Repository{ ObjectMeta: metav1.ObjectMeta{ diff --git a/test/e2e/framework/restore_session.go b/test/e2e/framework/restore_session.go index c8ef0d42a..77f388242 100644 --- a/test/e2e/framework/restore_session.go +++ b/test/e2e/framework/restore_session.go @@ -19,7 +19,6 @@ package framework import ( "context" "strings" - "time" "stash.appscode.dev/apimachinery/apis" "stash.appscode.dev/apimachinery/apis/stash/v1beta1" @@ -83,17 +82,6 @@ func (f *Framework) EventuallyRestoreProcessCompleted(meta metav1.ObjectMeta) Go ) } -func (f *Framework) EventuallyRestoreSessionPhase(meta metav1.ObjectMeta) GomegaAsyncAssertion { - return Eventually(func() v1beta1.RestoreSessionPhase { - restoreSession, err := f.StashClient.StashV1beta1().RestoreSessions(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) - Expect(err).NotTo(HaveOccurred()) - return restoreSession.Status.Phase - }, - time.Minute*7, - time.Second*7, - ) -} - func (f *Framework) GetRestoreJob(restoreSessionName string) (*batchv1.Job, error) { return f.KubeClient.BatchV1().Jobs(f.namespace).Get(context.TODO(), getRestoreJobName(restoreSessionName), metav1.GetOptions{}) } diff --git a/test/e2e/framework/service.go b/test/e2e/framework/service.go index 5a64f34d2..9a878cf3f 100644 --- a/test/e2e/framework/service.go +++ b/test/e2e/framework/service.go @@ -20,13 +20,7 @@ import ( "context" core "k8s.io/api/core/v1" - kerr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - core_util "kmodules.xyz/client-go/core/v1" -) - -const ( - TEST_HEADLESS_SERVICE = "headless" ) func (fi *Invocation) HeadlessService(name string) core.Service { @@ -53,19 +47,3 @@ func (fi *Invocation) HeadlessService(name string) core.Service { func (f *Framework) CreateService(obj core.Service) (*core.Service, error) { return f.KubeClient.CoreV1().Services(obj.Namespace).Create(context.TODO(), &obj, metav1.CreateOptions{}) } - -func (f *Framework) DeleteService(meta metav1.ObjectMeta) error { - err := f.KubeClient.CoreV1().Services(meta.Namespace).Delete(context.TODO(), meta.Name, *deleteInForeground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - -func (f *Framework) CreateOrPatchService(obj core.Service) error { - _, _, err := core_util.CreateOrPatchService(context.TODO(), f.KubeClient, obj.ObjectMeta, func(in *core.Service) *core.Service { - in.Spec = obj.Spec - return in - }, metav1.PatchOptions{}) - return err -} diff --git a/test/e2e/framework/statefulset.go b/test/e2e/framework/statefulset.go index c78eb8686..f3fc132c1 100644 --- a/test/e2e/framework/statefulset.go +++ b/test/e2e/framework/statefulset.go @@ -22,48 +22,19 @@ import ( "stash.appscode.dev/apimachinery/apis" - "github.com/appscode/go/crypto/rand" "github.com/appscode/go/types" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" - kerr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" kutil "kmodules.xyz/client-go" apps_util "kmodules.xyz/client-go/apps/v1" - meta_util "kmodules.xyz/client-go/meta" ) -func (fi *Invocation) StatefulSet(name, pvcName, volName string) apps.StatefulSet { - name = rand.WithUniqSuffix(fmt.Sprintf("%s-%s", name, fi.app)) - labels := map[string]string{ - "app": name, - "kind": "statefulset", - } - return apps.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: rand.WithUniqSuffix("stash"), - Namespace: fi.namespace, - Labels: labels, - }, - Spec: apps.StatefulSetSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - Replicas: types.Int32P(1), - Template: fi.PodTemplate(labels, pvcName, volName), - ServiceName: name, - UpdateStrategy: apps.StatefulSetUpdateStrategy{ - Type: apps.RollingUpdateStatefulSetStrategyType, - }, - }, - } -} - -func (fi *Invocation) StatefulSetForV1beta1API(name, volName string, replica int32) apps.StatefulSet { +func (fi *Invocation) StatefulSet(name, volName string, replica int32) apps.StatefulSet { labels := map[string]string{ "app": name, "kind": "statefulset", @@ -130,14 +101,6 @@ func (f *Framework) CreateStatefulSet(obj apps.StatefulSet) (*apps.StatefulSet, return f.KubeClient.AppsV1().StatefulSets(obj.Namespace).Create(context.TODO(), &obj, metav1.CreateOptions{}) } -func (f *Framework) DeleteStatefulSet(meta metav1.ObjectMeta) error { - err := f.KubeClient.AppsV1().StatefulSets(meta.Namespace).Delete(context.TODO(), meta.Name, meta_util.DeleteInBackground()) - if err != nil && !kerr.IsNotFound(err) { - return err - } - return nil -} - func (f *Framework) EventuallyStatefulSet(meta metav1.ObjectMeta) GomegaAsyncAssertion { return Eventually(func() *apps.StatefulSet { obj, err := f.KubeClient.AppsV1().StatefulSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}) @@ -174,38 +137,10 @@ func (fi *Invocation) WaitUntilStatefulSetReadyWithSidecar(meta metav1.ObjectMet }) } -func (fi *Invocation) WaitUntilStatefulSetWithInitContainer(meta metav1.ObjectMeta) error { - return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { - if obj, err := fi.KubeClient.AppsV1().StatefulSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err == nil { - if obj.Status.Replicas == obj.Status.ReadyReplicas { - pods, err := fi.GetAllPods(obj.ObjectMeta) - if err != nil { - return false, err - } - - for i := range pods { - hasInitContainer := false - for _, c := range pods[i].Spec.InitContainers { - if c.Name == apis.StashInitContainer { - hasInitContainer = true - } - } - if !hasInitContainer { - return false, nil - } - } - return true, nil - } - return false, nil - } - return false, nil - }) -} - func (fi *Invocation) DeployStatefulSet(name string, replica int32, volName string, transformFuncs ...func(ss *apps.StatefulSet)) (*apps.StatefulSet, error) { // Generate StatefulSet definition name = fmt.Sprintf("%s-%s", name, fi.app) - ss := fi.StatefulSetForV1beta1API(name, volName, replica) + ss := fi.StatefulSet(name, volName, replica) // transformFuncs provides a array of functions that made test specific change on the StatefulSet // apply these test specific changes diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index af4201edc..288039654 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -19,18 +19,14 @@ package framework import ( "context" "fmt" - "os/exec" "path/filepath" "strings" "time" "stash.appscode.dev/apimachinery/apis" - rep "stash.appscode.dev/apimachinery/apis/repositories/v1alpha1" api "stash.appscode.dev/apimachinery/apis/stash/v1alpha1" "stash.appscode.dev/apimachinery/apis/stash/v1beta1" cs "stash.appscode.dev/apimachinery/client/clientset/versioned" - "stash.appscode.dev/stash/pkg/eventer" - stash_rbac "stash.appscode.dev/stash/pkg/rbac" "github.com/appscode/go/sets" shell "github.com/codeskyblue/go-sh" @@ -44,7 +40,6 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" "kmodules.xyz/client-go/dynamic" meta_util "kmodules.xyz/client-go/meta" @@ -98,34 +93,6 @@ const ( TestUserID = 2000 ) -func (f *Framework) EventualEvent(meta metav1.ObjectMeta) GomegaAsyncAssertion { - return Eventually(func() []core.Event { - fieldSelector := fields.SelectorFromSet(fields.Set{ - "involvedObject.kind": "Repository", - "involvedObject.name": meta.Name, - "involvedObject.namespace": meta.Namespace, - "type": core.EventTypeNormal, - }) - events, err := f.KubeClient.CoreV1().Events(f.namespace).List(context.TODO(), metav1.ListOptions{FieldSelector: fieldSelector.String()}) - Expect(err).NotTo(HaveOccurred()) - return events.Items - }) -} - -func (f *Framework) EventualWarning(meta metav1.ObjectMeta, involvedObjectKind string) GomegaAsyncAssertion { - return Eventually(func() []core.Event { - fieldSelector := fields.SelectorFromSet(fields.Set{ - "involvedObject.kind": involvedObjectKind, - "involvedObject.name": meta.Name, - "involvedObject.namespace": meta.Namespace, - "type": core.EventTypeWarning, - }) - events, err := f.KubeClient.CoreV1().Events(f.namespace).List(context.TODO(), metav1.ListOptions{FieldSelector: fieldSelector.String()}) - Expect(err).NotTo(HaveOccurred()) - return events.Items - }) -} - func (f *Framework) EventuallyEvent(meta metav1.ObjectMeta, involvedObjectKind string) GomegaAsyncAssertion { return Eventually(func() []core.Event { fieldSelector := fields.SelectorFromSet(fields.Set{ @@ -140,125 +107,11 @@ func (f *Framework) EventuallyEvent(meta metav1.ObjectMeta, involvedObjectKind s }) } -func (f *Framework) CountSuccessfulBackups(events []core.Event) int { - count := 0 - for _, e := range events { - if e.Reason == eventer.EventReasonSuccessfulBackup { - count++ - } - } - return count -} - -func (f *Framework) CountFailedSetup(events []core.Event) int { - count := 0 - for _, e := range events { - if e.Reason == eventer.EventReasonFailedSetup { - count++ - } - } - return count -} - func deleteInForeground() *metav1.DeleteOptions { policy := metav1.DeletePropagationForeground return &metav1.DeleteOptions{PropagationPolicy: &policy} } -func CleanupMinikubeHostPath() error { - cmd := "minikube" - args := []string{"ssh", "sudo rm -rf /data/stash-test"} - return exec.Command(cmd, args...).Run() -} - -func (f *Framework) DeleteJobAndDependents(jobName string, recovery *api.Recovery) { - By("Checking Job deleted") - Eventually(func() bool { - _, err := f.KubeClient.BatchV1().Jobs(recovery.Namespace).Get(context.TODO(), jobName, metav1.GetOptions{}) - return kerr.IsNotFound(err) || kerr.IsGone(err) - }, time.Minute*3, time.Second*2).Should(BeTrue()) - - By("Checking pods deleted") - Eventually(func() bool { - pods, err := f.KubeClient.CoreV1().Pods(recovery.Namespace).List(context.TODO(), metav1.ListOptions{ - LabelSelector: "job-name=" + jobName, // pods created by job has a job-name label - }) - Expect(err).NotTo(HaveOccurred()) - return len(pods.Items) == 0 - }, time.Minute*3, time.Second*2).Should(BeTrue()) - - By("Checking service-account deleted") - Eventually(func() bool { - _, err := f.KubeClient.CoreV1().ServiceAccounts(recovery.Namespace).Get(context.TODO(), jobName, metav1.GetOptions{}) - return kerr.IsNotFound(err) || kerr.IsGone(err) - }, time.Minute*3, time.Second*2).Should(BeTrue()) - - By("Checking role-binding deleted") - Eventually(func() bool { - _, err := f.KubeClient.RbacV1().RoleBindings(recovery.Namespace).Get(context.TODO(), jobName, metav1.GetOptions{}) - return kerr.IsNotFound(err) || kerr.IsGone(err) - }, time.Minute*3, time.Second*2).Should(BeTrue()) - - By("Checking repo-reader role-binding deleted") - Eventually(func() bool { - _, err := f.KubeClient.RbacV1().RoleBindings(recovery.Spec.Repository.Namespace).Get(context.TODO(), stash_rbac.GetRepoReaderRoleBindingName(jobName, recovery.Namespace), metav1.GetOptions{}) - return kerr.IsNotFound(err) || kerr.IsGone(err) - }, time.Minute*3, time.Second*2).Should(BeTrue()) -} - -func (f *Framework) CreateDemoData(meta metav1.ObjectMeta) error { - err := f.CreateDirectory(meta, []string{TestSourceDataDir1, TestSourceDataDir2}) - if err != nil { - return err - } - err = f.CreateDataOnMountedDir(meta, []string{TestSourceDataDir1}, "file1.txt") - if err != nil { - return err - } - err = f.CreateDataOnMountedDir(meta, []string{TestSourceDataDir2}, "file2.txt") - if err != nil { - return err - } - return nil -} - -func (f *Framework) ReadSampleDataFromMountedDirectory(meta metav1.ObjectMeta, paths []string, resourceKind string) ([]string, error) { - switch resourceKind { - case apis.KindDeployment, apis.KindReplicaSet, apis.KindReplicationController: - pod, err := f.GetPod(meta) - if err != nil { - return nil, err - } - var data string - datas := make([]string, 0) - for _, p := range paths { - data, err = f.ExecOnPod(pod, "ls", p) - if err != nil { - return nil, err - } - datas = append(datas, data) - } - return datas, err - case apis.KindStatefulSet, apis.KindDaemonSet: - datas := make([]string, 0) - pods, err := f.GetAllPods(meta) - if err != nil { - return datas, err - } - for _, path := range paths { - for _, pod := range pods { - data, err := f.ExecOnPod(&pod, "ls", path) - if err != nil { - continue - } - datas = append(datas, data) - } - } - return datas, err - } - return []string{}, nil -} - func (f *Framework) ReadSampleDataFromFromWorkload(meta metav1.ObjectMeta, resourceKind string) ([]string, error) { switch resourceKind { case apis.KindDeployment, apis.KindReplicaSet, apis.KindReplicationController, apis.KindPod: @@ -291,339 +144,6 @@ func (f *Framework) ReadSampleDataFromFromWorkload(meta metav1.ObjectMeta, resou return nil, nil } -func (f *Framework) CreateDirectory(meta metav1.ObjectMeta, directories []string) error { - pod, err := f.GetPod(meta) - if err != nil { - return err - } - - for _, dir := range directories { - _, err := f.ExecOnPod(pod, "mkdir", "-p", dir) - if err != nil { - return err - } - } - return nil -} -func (f *Framework) CreateDataOnMountedDir(meta metav1.ObjectMeta, paths []string, fileName string) error { - pod, err := f.GetPod(meta) - if err != nil { - return err - } - for _, path := range paths { - _, err := f.ExecOnPod(pod, "touch", filepath.Join(path, fileName)) - if err != nil { - return err - } - - } - return nil -} - -func (fi *Invocation) HostPathVolumeWithMultipleDirectory() []core.Volume { - return []core.Volume{ - { - Name: TestSourceDataVolumeName, - VolumeSource: core.VolumeSource{ - HostPath: &core.HostPathVolumeSource{ - Path: filepath.Join(TestSoucreDemoDataPath, fi.app), - }, - }, - }, - } -} - -func FileGroupsForHostPathVolumeWithMultipleDirectory() []api.FileGroup { - return []api.FileGroup{ - { - Path: TestSourceDataDir1, - RetentionPolicyName: "keep-last-5", - }, - { - Path: TestSourceDataDir2, - RetentionPolicyName: "keep-last-5", - }, - } -} - -func (fi *Invocation) CleanupRecoveredVolume(meta metav1.ObjectMeta) error { - pod, err := fi.GetPod(meta) - if err != nil { - return err - } - _, err = fi.ExecOnPod(pod, "rm", "-rf", TestSourceDataMountPath) - if err != nil { - return err - } - return nil -} - -func (f *Framework) DaemonSetRepos(daemon *apps.DaemonSet) []*api.Repository { - return f.GetRepositories(KindMetaReplicas{Kind: apis.KindDaemonSet, Meta: daemon.ObjectMeta, Replicas: 1}) -} - -func (f *Framework) DeploymentRepos(deployment *apps.Deployment) []*api.Repository { - return f.GetRepositories(KindMetaReplicas{Kind: apis.KindDeployment, Meta: deployment.ObjectMeta, Replicas: int(*deployment.Spec.Replicas)}) -} - -func (f *Framework) ReplicationControllerRepos(rc *core.ReplicationController) []*api.Repository { - return f.GetRepositories(KindMetaReplicas{Kind: apis.KindReplicationController, Meta: rc.ObjectMeta, Replicas: int(*rc.Spec.Replicas)}) -} - -func (f *Framework) ReplicaSetRepos(rs *apps.ReplicaSet) []*api.Repository { - return f.GetRepositories(KindMetaReplicas{Kind: apis.KindReplicaSet, Meta: rs.ObjectMeta, Replicas: int(*rs.Spec.Replicas)}) -} - -func (f *Framework) StatefulSetRepos(ss *apps.StatefulSet) []*api.Repository { - return f.GetRepositories(KindMetaReplicas{Kind: apis.KindStatefulSet, Meta: ss.ObjectMeta, Replicas: int(*ss.Spec.Replicas)}) -} - -func (f *Framework) LatestSnapshot(snapshots []rep.Snapshot) rep.Snapshot { - latestSnapshot := snapshots[0] - for _, snap := range snapshots { - if snap.CreationTimestamp.After(latestSnapshot.CreationTimestamp.Time) { - latestSnapshot = snap - } - } - return latestSnapshot -} - -func GetPathsFromResticFileGroups(restic *api.Restic) []string { - paths := make([]string, 0) - for _, fg := range restic.Spec.FileGroups { - paths = append(paths, fg.Path) - } - return paths -} - -func GetPathsFromRestoreSession(restoreSession *v1beta1.RestoreSession) []string { - paths := make([]string, 0) - for i := range restoreSession.Spec.Rules { - paths = append(paths, restoreSession.Spec.Rules[i].Paths...) - } - paths = removeDuplicates(paths) - return paths -} - -func removeDuplicates(elements []string) []string { - encountered := map[string]bool{} - - // Create a map of all unique elements. - for v := range elements { - encountered[elements[v]] = true - } - - // Place all keys from the map into a slice. - result := []string{} - for key := range encountered { - result = append(result, key) - } - return result -} - -func (f *Framework) EventuallyJobSucceed(name string) GomegaAsyncAssertion { - jobCreated := false - return Eventually(func() bool { - obj, err := f.KubeClient.BatchV1().Jobs(f.namespace).Get(context.TODO(), name, metav1.GetOptions{}) - if err != nil && !kerr.IsNotFound(err) { - Expect(err).NotTo(HaveOccurred()) - } - - if err != nil && kerr.IsNotFound(err) && jobCreated { - return true - } - - jobCreated = true - return obj.Status.Succeeded > 0 - }, time.Minute*5, time.Second*5) -} - -func WaitUntilNamespaceDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.CoreV1().Namespaces().Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilDeploymentDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.AppsV1().Deployments(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilDaemonSetDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.AppsV1().DaemonSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilStatefulSetDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.AppsV1().StatefulSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilReplicaSetDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.AppsV1().ReplicaSets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilReplicationControllerDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.CoreV1().ReplicationControllers(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilSecretDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.CoreV1().Secrets(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilServiceDeleted(kc kubernetes.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := kc.CoreV1().Services(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilResticDeleted(sc cs.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := sc.StashV1alpha1().Restics(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilBackupConfigurationDeleted(sc cs.Interface, meta metav1.ObjectMeta) error { - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := sc.StashV1beta1().BackupConfigurations(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilRestoreSessionDeleted(sc cs.Interface, meta metav1.ObjectMeta) error { - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := sc.StashV1beta1().RestoreSessions(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilRecoveryDeleted(sc cs.Interface, meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - if _, err := sc.StashV1alpha1().Recoveries(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - return true, nil - } else { - return true, err - } - } - return false, nil - }) -} - -func WaitUntilRepositoriesDeleted(sc cs.Interface, repositories []*api.Repository) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - allDeleted := true - for _, repo := range repositories { - if _, err := sc.StashV1alpha1().Repositories(repo.Namespace).Get(context.TODO(), repo.Name, metav1.GetOptions{}); err != nil { - if kerr.IsNotFound(err) { - continue - } else { - return true, err - } - } - allDeleted = false - } - if allDeleted { - return true, nil - } - return false, nil - }) -} func WaitUntilRepositoryDeleted(sc cs.Interface, repository *api.Repository) error { return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { @@ -638,21 +158,6 @@ func WaitUntilRepositoryDeleted(sc cs.Interface, repository *api.Repository) err }) } -func (f *Framework) WaitUntilDaemonPodReady(meta metav1.ObjectMeta) error { - - return wait.PollImmediate(PullInterval, WaitTimeOut, func() (done bool, err error) { - pod, err := f.GetPod(meta) - if err != nil { - return false, nil - } - if pod.Status.Phase == core.PodPhase(core.PodRunning) { - return true, nil - } - return false, nil - - }) -} - func (f *Framework) GetNodeName(meta metav1.ObjectMeta) string { pod, err := f.GetPod(meta) if err == nil { @@ -725,15 +230,6 @@ func (fi *Invocation) CleanupSampleDataFromWorkload(meta metav1.ObjectMeta, reso return nil } -func (fi *Invocation) ReadDataFromPod(meta metav1.ObjectMeta) (data string, err error) { - pod, err := fi.GetPod(meta) - if err != nil { - return "", err - } - data, err = fi.ExecOnPod(pod, "ls", "-R", TestSourceDataMountPath) - return data, err -} - func (fi *Invocation) AppendToCleanupList(resources ...interface{}) { for i := range resources { fi.testResources = append(fi.testResources, resources[i]) diff --git a/test/e2e/matcher/replica_matcher.go b/test/e2e/matcher/replica_matcher.go deleted file mode 100644 index 7ebb42709..000000000 --- a/test/e2e/matcher/replica_matcher.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright The Stash Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package matcher - -import ( - "fmt" - - "github.com/onsi/gomega/types" - apps "k8s.io/api/apps/v1" - core "k8s.io/api/core/v1" -) - -func HaveReplica(expected int) types.GomegaMatcher { - return &replicaMatcher{ - expected: expected, - } -} - -type replicaMatcher struct { - expected int -} - -func (matcher *replicaMatcher) Match(actual interface{}) (success bool, err error) { - switch obj := actual.(type) { - case *core.ReplicationController: - return *obj.Spec.Replicas == int32(matcher.expected), nil - case *apps.ReplicaSet: - return *obj.Spec.Replicas == int32(matcher.expected), nil - case *apps.Deployment: - return *obj.Spec.Replicas == int32(matcher.expected), nil - //case *extensions.DaemonSet: - // return matcher.find(obj.Spec.Template.Spec.Containers) - //case *apps.StatefulSet: - // return matcher.find(obj.Spec.Template.Spec.Containers) - - default: - return false, fmt.Errorf("Unknown object type") - } -} - -func (matcher *replicaMatcher) FailureMessage(actual interface{}) (message string) { - return fmt.Sprintf("Expected\n\t%#v\n to have \n\t%#v replica", actual, matcher.expected) -} - -func (matcher *replicaMatcher) NegatedFailureMessage(actual interface{}) (message string) { - return fmt.Sprintf("Expected\n\t%#v\n not to have\n\t%#v replica", actual, matcher.expected) -}