Skip to content

Commit

Permalink
Remove unnecessary test codes + run test in parallel
Browse files Browse the repository at this point in the history
Signed-off-by: hossainemruz <[email protected]>
  • Loading branch information
hossainemruz committed Jun 4, 2020
1 parent 8a780e0 commit 4342808
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 894 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ jobs:
make install
echo
sleep 10
make e2e-tests
make e2e-parallel
38 changes: 0 additions & 38 deletions test/e2e/framework/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 0 additions & 37 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down
42 changes: 22 additions & 20 deletions test/e2e/framework/minio_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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),
Expand All @@ -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{
Expand Down Expand Up @@ -174,15 +177,15 @@ 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,
},
},
},
{
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,
Expand Down Expand Up @@ -225,7 +228,6 @@ func (f *Framework) DeploymentForMinioServer() apps.Deployment {
Ports: []core.ContainerPort{
{
ContainerPort: int32(443),
HostPort: int32(443),
},
},
VolumeMounts: []core.VolumeMount{
Expand All @@ -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)
}
Expand All @@ -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),
},
},
}
Expand Down
1 change: 0 additions & 1 deletion test/e2e/framework/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions test/e2e/framework/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 0 additions & 37 deletions test/e2e/framework/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 4342808

Please sign in to comment.