mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
fix e2e test of kube schematic (#1321)
* fix kube schematic Signed-off-by: roywang <seiwy2010@gmail.com> * fix e2e test Signed-off-by: roywang <seiwy2010@gmail.com>
This commit is contained in:
@@ -100,11 +100,11 @@ Deploy the `Application` and verify the resulting workload.
|
||||
```shell
|
||||
$ kubectl get deploy
|
||||
NAME READY UP-TO-DATE AVAILABLE AGE
|
||||
mycomp-v1 1/1 1 1 66m
|
||||
mycomp 1/1 1 1 66m
|
||||
```
|
||||
And check the parameter works.
|
||||
```shell
|
||||
$ kubectl get deployment mycomp-v1 -o json | jq '.spec.template.spec.containers[0].image'
|
||||
$ kubectl get deployment mycomp -o json | jq '.spec.template.spec.containers[0].image'
|
||||
"nginx:1.14.0"
|
||||
```
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ NAME AGE
|
||||
demo-podinfo-scaler-3x1sfcd34 2m
|
||||
```
|
||||
```shell
|
||||
$ kubectl get deployment mycomp-v1 -o json | jq .spec.replicas
|
||||
$ kubectl get deployment mycomp -o json | jq .spec.replicas
|
||||
2
|
||||
```
|
||||
|
||||
Check the virtualgroup trait.
|
||||
```shell
|
||||
$ kubectl get deployment mycomp-v1 -o json | jq .spec.template.metadata.labels
|
||||
$ kubectl get deployment mycomp -o json | jq .spec.template.metadata.labels
|
||||
{
|
||||
"app.cluster.virtual.group": "my-group1",
|
||||
"app.kubernetes.io/name": "myapp"
|
||||
@@ -84,23 +84,21 @@ spec:
|
||||
|
||||
Apply the new configuration and check the results after several seconds.
|
||||
|
||||
> After updating, the workload name is changed from `mycomp-v1` to `mycomp-v2`.
|
||||
|
||||
Check the new parameter works.
|
||||
```shell
|
||||
$ kubectl get deployment mycomp-v2 -o json | jq '.spec.template.spec.containers[0].image'
|
||||
$ kubectl get deployment mycomp -o json | jq '.spec.template.spec.containers[0].image'
|
||||
"nginx:1.14.1"
|
||||
```
|
||||
|
||||
Check the scaler trait.
|
||||
```shell
|
||||
$ kubectl get deployment mycomp-v2 -o json | jq .spec.replicas
|
||||
$ kubectl get deployment mycomp -o json | jq .spec.replicas
|
||||
4
|
||||
```
|
||||
|
||||
Check the virtualgroup trait.
|
||||
```shell
|
||||
$ kubectl get deployment mycomp-v2 -o json | jq .spec.template.metadata.labels
|
||||
$ kubectl get deployment mycomp -o json | jq .spec.template.metadata.labels
|
||||
{
|
||||
"app.cluster.virtual.group": "my-group2",
|
||||
"app.kubernetes.io/name": "myapp"
|
||||
|
||||
@@ -121,7 +121,7 @@ var _ = Describe("Application Normal tests", func() {
|
||||
}
|
||||
return nil
|
||||
},
|
||||
time.Second*30, time.Millisecond*500).Should(BeNil())
|
||||
time.Second*60, time.Millisecond*500).Should(BeNil())
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
|
||||
@@ -39,32 +39,19 @@ import (
|
||||
var _ = Describe("Test application containing helm module", func() {
|
||||
ctx := context.Background()
|
||||
var (
|
||||
namespace = "helm-test-ns"
|
||||
appName = "test-app"
|
||||
compName = "test-comp"
|
||||
cdName = "webapp-chart"
|
||||
wdName = "webapp-chart-wd"
|
||||
tdName = "virtualgroup"
|
||||
appName = "test-app"
|
||||
compName = "test-comp"
|
||||
cdName = "webapp-chart"
|
||||
wdName = "webapp-chart-wd"
|
||||
tdName = "virtualgroup"
|
||||
)
|
||||
var namespace string
|
||||
var app v1alpha2.Application
|
||||
var ns corev1.Namespace
|
||||
|
||||
BeforeEach(func() {
|
||||
namespace = randomNamespaceName("helm-e2e-test")
|
||||
ns = corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
|
||||
Eventually(
|
||||
func() error {
|
||||
return k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground))
|
||||
},
|
||||
time.Second*120, time.Millisecond*500).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{}))
|
||||
By("make sure all the resources are removed")
|
||||
objectKey := client.ObjectKey{
|
||||
Name: namespace,
|
||||
}
|
||||
Eventually(
|
||||
func() error {
|
||||
return k8sClient.Get(ctx, objectKey, &corev1.Namespace{})
|
||||
},
|
||||
time.Second*120, time.Millisecond*500).Should(&util.NotFoundMatcher{})
|
||||
Eventually(
|
||||
func() error {
|
||||
return k8sClient.Create(ctx, &ns)
|
||||
@@ -133,8 +120,8 @@ var _ = Describe("Test application containing helm module", func() {
|
||||
k8sClient.DeleteAllOf(ctx, &v1alpha2.ComponentDefinition{}, client.InNamespace(namespace))
|
||||
k8sClient.DeleteAllOf(ctx, &v1alpha2.WorkloadDefinition{}, client.InNamespace(namespace))
|
||||
k8sClient.DeleteAllOf(ctx, &v1alpha2.TraitDefinition{}, client.InNamespace(namespace))
|
||||
By(fmt.Sprintf("Delete the entire namespaceName %s", ns.Name))
|
||||
Expect(k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground))).Should(Succeed())
|
||||
time.Sleep(15 * time.Second)
|
||||
|
||||
By("Remove 'deployments.apps' from scaler's appliesToWorkloads")
|
||||
scalerTd := v1alpha2.TraitDefinition{}
|
||||
@@ -285,7 +272,7 @@ var _ = Describe("Test application containing helm module", func() {
|
||||
}
|
||||
By("Verify new application's settings override chart default values")
|
||||
return strings.HasSuffix(deploy.Spec.Template.Spec.Containers[0].Image, "5.1.3")
|
||||
}, 60*time.Second, 10*time.Second).Should(BeTrue())
|
||||
}, 120*time.Second, 10*time.Second).Should(BeTrue())
|
||||
})
|
||||
|
||||
It("Test deploy an application containing helm module defined by workloadDefinition", func() {
|
||||
|
||||
@@ -42,13 +42,13 @@ import (
|
||||
var _ = Describe("Test application containing kube module", func() {
|
||||
ctx := context.Background()
|
||||
var (
|
||||
namespace = "kube-test-ns"
|
||||
appName = "test-app"
|
||||
compName = "test-comp"
|
||||
cdName = "test-kube-worker"
|
||||
wdName = "test-kube-worker-wd"
|
||||
tdName = "test-virtualgroup"
|
||||
appName = "test-app"
|
||||
compName = "test-comp"
|
||||
cdName = "test-kube-worker"
|
||||
wdName = "test-kube-worker-wd"
|
||||
tdName = "test-virtualgroup"
|
||||
)
|
||||
var namespace string
|
||||
var app v1beta1.Application
|
||||
var ns corev1.Namespace
|
||||
|
||||
@@ -73,17 +73,8 @@ spec:
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
namespace = randomNamespaceName("kube-e2e-test")
|
||||
ns = corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
|
||||
Eventually(
|
||||
func() error {
|
||||
return k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground))
|
||||
},
|
||||
time.Second*120, time.Millisecond*500).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{}))
|
||||
By("make sure all the resources are removed")
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: namespace}, &corev1.Namespace{})
|
||||
}, time.Second*120, time.Millisecond*500).Should(&util.NotFoundMatcher{})
|
||||
By("create test namespace")
|
||||
Eventually(
|
||||
func() error {
|
||||
return k8sClient.Create(ctx, &ns)
|
||||
@@ -151,11 +142,8 @@ spec:
|
||||
k8sClient.DeleteAllOf(ctx, &v1beta1.ComponentDefinition{}, client.InNamespace(namespace))
|
||||
k8sClient.DeleteAllOf(ctx, &v1beta1.WorkloadDefinition{}, client.InNamespace(namespace))
|
||||
k8sClient.DeleteAllOf(ctx, &v1beta1.TraitDefinition{}, client.InNamespace(namespace))
|
||||
By(fmt.Sprintf("Delete the entire namespaceName %s", ns.Name))
|
||||
Expect(k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground))).Should(Succeed())
|
||||
By("make sure all the resources are removed")
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: namespace}, &corev1.Namespace{})
|
||||
}, time.Second*120, time.Millisecond*500).Should(&util.NotFoundMatcher{})
|
||||
|
||||
By("Remove 'deployments.apps' from scaler's appliesToWorkloads")
|
||||
scalerTd := v1beta1.TraitDefinition{}
|
||||
@@ -203,14 +191,17 @@ spec:
|
||||
|
||||
ac := &v1alpha2.ApplicationContext{}
|
||||
acName := appName
|
||||
By("Verify the ApplicationContext is created successfully")
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: acName, Namespace: namespace}, ac)
|
||||
}, 30*time.Second, time.Second).Should(Succeed())
|
||||
By("Verify the ApplicationContext is created & reconciled successfully")
|
||||
Eventually(func() bool {
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: acName, Namespace: namespace}, ac); err != nil {
|
||||
return false
|
||||
}
|
||||
return len(ac.Status.Workloads) > 0
|
||||
}, 15*time.Second, time.Second).Should(BeTrue())
|
||||
|
||||
By("Verify the workload(deployment) is created successfully")
|
||||
deploy := &appsv1.Deployment{}
|
||||
deployName := fmt.Sprintf("%s-v1", compName)
|
||||
deployName := ac.Status.Workloads[0].Reference.Name
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: deployName, Namespace: namespace}, deploy)
|
||||
}, 30*time.Second, 3*time.Second).Should(Succeed())
|
||||
@@ -270,18 +261,19 @@ spec:
|
||||
}
|
||||
Expect(k8sClient.Patch(ctx, &app, client.Merge)).Should(Succeed())
|
||||
|
||||
By("Verify the ApplicationContext is updated")
|
||||
deploy = &appsv1.Deployment{}
|
||||
By("Verify the ApplicationContext is update successfully")
|
||||
Eventually(func() bool {
|
||||
ac = &v1alpha2.ApplicationContext{}
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: acName, Namespace: namespace}, ac); err != nil {
|
||||
return false
|
||||
}
|
||||
return ac.GetGeneration() == 2
|
||||
}, 15*time.Second, 3*time.Second).Should(BeTrue())
|
||||
return ac.Generation == 2
|
||||
}, 10*time.Second, time.Second).Should(BeTrue())
|
||||
|
||||
By("Verify the workload(deployment) is created successfully")
|
||||
deploy = &appsv1.Deployment{}
|
||||
deployName = ac.Status.Workloads[0].Reference.Name
|
||||
|
||||
By("Verify the changes are applied to the workload")
|
||||
deployName = fmt.Sprintf("%s-v2", compName)
|
||||
Eventually(func() bool {
|
||||
requestReconcileNow(ctx, ac)
|
||||
deploy := &appsv1.Deployment{}
|
||||
@@ -347,14 +339,17 @@ spec:
|
||||
|
||||
ac := &v1alpha2.ApplicationContext{}
|
||||
acName := appTestName
|
||||
By("Verify the AppConfig is created successfully")
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: acName, Namespace: namespace}, ac)
|
||||
}, 30*time.Second, time.Second).Should(Succeed())
|
||||
By("Verify the ApplicationContext is created & reconciled successfully")
|
||||
Eventually(func() bool {
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: acName, Namespace: namespace}, ac); err != nil {
|
||||
return false
|
||||
}
|
||||
return len(ac.Status.Workloads) > 0
|
||||
}, 15*time.Second, time.Second).Should(BeTrue())
|
||||
|
||||
By("Verify the workload(deployment) is created successfully")
|
||||
deploy := &appsv1.Deployment{}
|
||||
deployName := fmt.Sprintf("%s-v1", compName)
|
||||
deployName := ac.Status.Workloads[0].Reference.Name
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: deployName, Namespace: namespace}, deploy)
|
||||
}, 15*time.Second, 3*time.Second).Should(Succeed())
|
||||
|
||||
@@ -19,8 +19,6 @@ package controllers_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -236,7 +234,7 @@ var _ = Describe("Cloneset based rollout tests", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
By("Start to run a test, clean up previous resources")
|
||||
namespaceName = "rolling-e2e-test" + "-" + strconv.FormatInt(rand.Int63(), 16)
|
||||
namespaceName = randomNamespaceName("rolling-e2e-test")
|
||||
createNamespace()
|
||||
})
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -300,8 +301,6 @@ var _ = AfterSuite(func() {
|
||||
// This is a workaround to avoid long-time wait before next scheduled
|
||||
// reconciliation.
|
||||
func requestReconcileNow(ctx context.Context, o runtime.Object) {
|
||||
By(fmt.Sprintf("Requset reconcile %q now",
|
||||
o.GetObjectKind().GroupVersionKind().String()))
|
||||
oCopy := o.DeepCopyObject()
|
||||
oMeta, ok := oCopy.(metav1.Object)
|
||||
Expect(ok).Should(BeTrue())
|
||||
@@ -309,5 +308,13 @@ func requestReconcileNow(ctx context.Context, o runtime.Object) {
|
||||
"app.oam.dev/requestreconcile": time.Now().String(),
|
||||
})
|
||||
oMeta.SetResourceVersion("")
|
||||
By(fmt.Sprintf("Requset reconcile %q now", oMeta.GetName()))
|
||||
Expect(k8sClient.Patch(ctx, oCopy, client.Merge)).Should(Succeed())
|
||||
}
|
||||
|
||||
// randomNamespaceName generates a random name based on the basic name.
|
||||
// Running each ginkgo case in a new namespace with a random name can avoid
|
||||
// waiting a long time to GC namesapce.
|
||||
func randomNamespaceName(basic string) string {
|
||||
return fmt.Sprintf("%s-%s", basic, strconv.FormatInt(rand.Int63(), 16))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user