Skip to content

Commit

Permalink
Use kutil in e2e-test (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mir Shahriar authored and tamalsaha committed Sep 14, 2017
1 parent f5e8c2e commit cb2e2c0
Show file tree
Hide file tree
Showing 443 changed files with 85,822 additions and 42,792 deletions.
63 changes: 55 additions & 8 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ import:
version: 1fd2e63a9a370677308a42f24fd40c86438afddf
- package: k8s.io/client-go
version: v4.0.0
- package: github.com/appscode/kutil
version: release-4.0
- package: k8s.io/apiextensions-apiserver
version: 5fa44608f6b9b2180a2fd1ecb52e651fd0397794
- package: github.com/hashicorp/go-version
repo: https://github.com/appscode/go-version.git
vcs: git
version: master
testImport:
- package: github.com/mitchellh/go-homedir
- package: github.com/onsi/ginkgo
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ var _ = BeforeSuite(func() {
slService := root.Invoke().ServiceSearchlight()
err = root.CreateService(slService)
Expect(err).NotTo(HaveOccurred())
root.EventuallyServiceLoadBalancer(slService.ObjectMeta, "icinga").Should(BeTrue())
root.EventuallyServiceLoadBalancer(slService.ObjectMeta, "api").Should(BeTrue())

// Get Icinga Ingress Hostname
endpoint, err := root.GetServiceEndpoint(slService.ObjectMeta, "icinga")
endpoint, err := root.GetServiceEndpoint(slService.ObjectMeta, "api")
Expect(err).NotTo(HaveOccurred())

// Icinga Config
Expand Down
24 changes: 3 additions & 21 deletions test/e2e/framework/clusteralerts.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package framework

import (
"fmt"
"time"

"github.com/appscode/go/crypto/rand"
"github.com/appscode/log"
kutilsl "github.com/appscode/kutil/searchlight/v1alpha1"
tapi "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
"github.com/appscode/searchlight/pkg/icinga"
"github.com/appscode/searchlight/test/e2e/matcher"
Expand Down Expand Up @@ -38,25 +37,8 @@ func (f *Framework) GetClusterAlert(meta metav1.ObjectMeta) (*tapi.ClusterAlert,
return f.extClient.ClusterAlerts(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
}

func (f *Framework) UpdateClusterAlert(meta metav1.ObjectMeta, transformer func(tapi.ClusterAlert) tapi.ClusterAlert) (*tapi.ClusterAlert, error) {
attempt := 0
for ; attempt < maxAttempts; attempt = attempt + 1 {
cur, err := f.extClient.ClusterAlerts(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

modified := transformer(*cur)
updated, err := f.extClient.ClusterAlerts(cur.Namespace).Update(&modified)
if err == nil {
return updated, nil
}

log.Errorf("Attempt %d failed to update ClusterAlert %s@%s due to %s.", attempt, cur.Name, cur.Namespace, err)
time.Sleep(updateRetryInterval)
}

return nil, fmt.Errorf("Failed to update ClusterAlert %s@%s after %d attempts.", meta.Name, meta.Namespace, attempt)
func (f *Framework) TryPatchClusterAlert(meta metav1.ObjectMeta, transform func(*tapi.ClusterAlert) *tapi.ClusterAlert) (*tapi.ClusterAlert, error) {
return kutilsl.TryPatchClusterAlert(f.extClient, meta, transform)
}

func (f *Framework) DeleteClusterAlert(meta metav1.ObjectMeta) error {
Expand Down
52 changes: 10 additions & 42 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package framework

import (
"fmt"
"time"

"github.com/appscode/go/crypto/rand"
"github.com/appscode/go/types"
"github.com/appscode/log"
kutilapps "github.com/appscode/kutil/apps/v1beta1"
kutilext "github.com/appscode/kutil/extensions/v1beta1"
. "github.com/onsi/gomega"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -41,32 +41,16 @@ func (f *Framework) CreateDeploymentApp(obj *apps.Deployment) error {
return err
}

func (f *Framework) UpdateDeploymentApp(meta metav1.ObjectMeta, transformer func(apps.Deployment) apps.Deployment) (*apps.Deployment, error) {
attempt := 0
for ; attempt < maxAttempts; attempt = attempt + 1 {
cur, err := f.kubeClient.AppsV1beta1().Deployments(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

modified := transformer(*cur)
updated, err := f.kubeClient.AppsV1beta1().Deployments(cur.Namespace).Update(&modified)
if err == nil {
return updated, nil
}

log.Errorf("Attempt %d failed to update Deployments %s@%s due to %s.", attempt, cur.Name, cur.Namespace, err)
time.Sleep(updateRetryInterval)
}

return nil, fmt.Errorf("Failed to update Deployments %s@%s after %d attempts.", meta.Name, meta.Namespace, attempt)
func (f *Framework) TryPatchDeploymentApp(meta metav1.ObjectMeta, transformer func(*apps.Deployment) *apps.Deployment) (*apps.Deployment, error) {
return kutilapps.TryPatchDeployment(f.kubeClient, meta, transformer)
}

func (f *Framework) EventuallyDeleteDeploymentApp(meta metav1.ObjectMeta) GomegaAsyncAssertion {
deployment, err := f.UpdateDeploymentApp(meta, func(in apps.Deployment) apps.Deployment {
deployment, err := f.TryPatchDeploymentApp(meta, func(in *apps.Deployment) *apps.Deployment {
in.Spec.Replicas = types.Int32P(0)
return in
})

if kerr.IsNotFound(err) {
return Eventually(func() bool { return true })
}
Expand Down Expand Up @@ -125,32 +109,16 @@ func (f *Framework) CreateDeploymentExtension(obj *extensions.Deployment) error
return err
}

func (f *Framework) UpdateDeploymentExtension(meta metav1.ObjectMeta, transformer func(extensions.Deployment) extensions.Deployment) (*extensions.Deployment, error) {
attempt := 0
for ; attempt < maxAttempts; attempt = attempt + 1 {
cur, err := f.kubeClient.ExtensionsV1beta1().Deployments(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

modified := transformer(*cur)
updated, err := f.kubeClient.ExtensionsV1beta1().Deployments(cur.Namespace).Update(&modified)
if err == nil {
return updated, nil
}

log.Errorf("Attempt %d failed to update Deployments %s@%s due to %s.", attempt, cur.Name, cur.Namespace, err)
time.Sleep(updateRetryInterval)
}

return nil, fmt.Errorf("Failed to update Deployments %s@%s after %d attempts.", meta.Name, meta.Namespace, attempt)
func (f *Framework) TryPatchDeploymentExt(meta metav1.ObjectMeta, transformer func(*extensions.Deployment) *extensions.Deployment) (*extensions.Deployment, error) {
return kutilext.TryPatchDeployment(f.kubeClient, meta, transformer)
}

func (f *Framework) EventuallyDeleteDeploymentExtension(meta metav1.ObjectMeta) GomegaAsyncAssertion {
deployment, err := f.UpdateDeploymentExtension(meta, func(in extensions.Deployment) extensions.Deployment {
deployment, err := f.TryPatchDeploymentExt(meta, func(in *extensions.Deployment) *extensions.Deployment {
in.Spec.Replicas = types.Int32P(0)
return in
})

if kerr.IsNotFound(err) {
return Eventually(func() bool { return true })
}
Expand Down
26 changes: 4 additions & 22 deletions test/e2e/framework/replicaset.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package framework

import (
"fmt"
"time"

"github.com/appscode/go/crypto/rand"
"github.com/appscode/go/types"
"github.com/appscode/log"
kutilext "github.com/appscode/kutil/extensions/v1beta1"
. "github.com/onsi/gomega"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -43,29 +42,12 @@ func (f *Framework) CreateReplicaSet(obj *extensions.ReplicaSet) (*extensions.Re
return f.kubeClient.ExtensionsV1beta1().ReplicaSets(obj.Namespace).Create(obj)
}

func (f *Framework) UpdateReplicaSet(meta metav1.ObjectMeta, transformer func(extensions.ReplicaSet) extensions.ReplicaSet) (*extensions.ReplicaSet, error) {
attempt := 0
for ; attempt < maxAttempts; attempt = attempt + 1 {
cur, err := f.kubeClient.ExtensionsV1beta1().ReplicaSets(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

modified := transformer(*cur)
updated, err := f.kubeClient.ExtensionsV1beta1().ReplicaSets(cur.Namespace).Update(&modified)
if err == nil {
return updated, nil
}

log.Errorf("Attempt %d failed to update ReplicaSets %s@%s due to %s.", attempt, cur.Name, cur.Namespace, err)
time.Sleep(updateRetryInterval)
}

return nil, fmt.Errorf("Failed to update ReplicaSets %s@%s after %d attempts.", meta.Name, meta.Namespace, attempt)
func (f *Framework) TryPatchReplicaSet(meta metav1.ObjectMeta, transformer func(*extensions.ReplicaSet) *extensions.ReplicaSet) (*extensions.ReplicaSet, error) {
return kutilext.TryPatchReplicaSet(f.kubeClient, meta, transformer)
}

func (f *Framework) EventuallyDeleteReplicaSet(meta metav1.ObjectMeta) GomegaAsyncAssertion {
rs, err := f.UpdateReplicaSet(meta, func(in extensions.ReplicaSet) extensions.ReplicaSet {
rs, err := f.TryPatchReplicaSet(meta, func(in *extensions.ReplicaSet) *extensions.ReplicaSet {
in.Spec.Replicas = types.Int32P(0)
return in
})
Expand Down
26 changes: 4 additions & 22 deletions test/e2e/framework/statefulset.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package framework

import (
"fmt"
"time"

"github.com/appscode/go/crypto/rand"
"github.com/appscode/go/types"
"github.com/appscode/log"
kutilapps "github.com/appscode/kutil/apps/v1beta1"
. "github.com/onsi/gomega"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -69,29 +68,12 @@ func (f *Framework) CreateStatefulSet(obj *apps.StatefulSet) (*apps.StatefulSet,
return f.kubeClient.AppsV1beta1().StatefulSets(obj.Namespace).Create(obj)
}

func (f *Framework) UpdateStatefulSet(meta metav1.ObjectMeta, transformer func(apps.StatefulSet) apps.StatefulSet) (*apps.StatefulSet, error) {
attempt := 0
for ; attempt < maxAttempts; attempt = attempt + 1 {
cur, err := f.kubeClient.AppsV1beta1().StatefulSets(meta.Namespace).Get(meta.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

modified := transformer(*cur)
updated, err := f.kubeClient.AppsV1beta1().StatefulSets(cur.Namespace).Update(&modified)
if err == nil {
return updated, nil
}

log.Errorf("Attempt %d failed to update StatefulSets %s@%s due to %s.", attempt, cur.Name, cur.Namespace, err)
time.Sleep(updateRetryInterval)
}

return nil, fmt.Errorf("Failed to update StatefulSets %s@%s after %d attempts.", meta.Name, meta.Namespace, attempt)
func (f *Framework) TryPatchStatefulSet(meta metav1.ObjectMeta, transformer func(*apps.StatefulSet) *apps.StatefulSet) (*apps.StatefulSet, error) {
return kutilapps.TryPatchStatefulSet(f.kubeClient, meta, transformer)
}

func (f *Framework) EventuallyDeleteStatefulSet(meta metav1.ObjectMeta) GomegaAsyncAssertion {
ss, err := f.UpdateStatefulSet(meta, func(in apps.StatefulSet) apps.StatefulSet {
ss, err := f.TryPatchStatefulSet(meta, func(in *apps.StatefulSet) *apps.StatefulSet {
in.Spec.Replicas = types.Int32P(0)
return in
})
Expand Down
Loading

0 comments on commit cb2e2c0

Please sign in to comment.