Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine e2e testings. #205

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ e2e-test: e2e-test/teardown e2e-test/setup
${PWD}/test/e2e/pkg -- \
-api-server=https://$(shell cat ${PWD}/test/e2e/.external_host_ip):30080 \
-grpc-server=$(shell cat ${PWD}/test/e2e/.external_host_ip):30090 \
-server-kubeconfig=${PWD}/test/e2e/.kubeconfig \
-consumer-name=$(shell cat ${PWD}/test/e2e/.consumer_name) \
-consumer-kubeconfig=${PWD}/test/e2e/.kubeconfig
-agent-kubeconfig=${PWD}/test/e2e/.kubeconfig
.PHONY: e2e-test
24 changes: 12 additions & 12 deletions test/e2e/pkg/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {
})

It("publish a resource spec using grpc client", func() {
evt := helper.NewEvent(sourceID, "create_request", consumer.Name, resourceID, deployName, 1, 1)
evt := helper.NewEvent(sourceID, "create_request", agentTestOpts.consumerName, resourceID, deployName, 1, 1)
pbEvt := &pbv1.CloudEvent{}
err := grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt)
Expect(err).To(BeNil(), "failed to convert spec from cloudevent to protobuf")
Expand Down Expand Up @@ -132,7 +132,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {

It("get the nginx deployment from cluster", func() {
Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -152,7 +152,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {
})

It("publish a resource spec with update request using grpc client", func() {
evt := helper.NewEvent(sourceID, "update_request", consumer.Name, resourceID, deployName, 1, 2)
evt := helper.NewEvent(sourceID, "update_request", agentTestOpts.consumerName, resourceID, deployName, 1, 2)
pbEvt := &pbv1.CloudEvent{}
err := grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt)
Expect(err).To(BeNil(), "failed to convert spec from cloudevent to protobuf")
Expand Down Expand Up @@ -189,7 +189,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {

It("get the nginx deployment from cluster", func() {
Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -209,7 +209,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {
})

It("publish a resource spec with delete request using grpc client", func() {
evt := helper.NewEvent(sourceID, "delete_request", consumer.Name, resourceID, deployName, 2, 2)
evt := helper.NewEvent(sourceID, "delete_request", agentTestOpts.consumerName, resourceID, deployName, 2, 2)
pbEvt := &pbv1.CloudEvent{}
err := grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt)
Expect(err).To(BeNil(), "failed to convert spec from cloudevent to protobuf")
Expand All @@ -233,7 +233,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {

It("get the nginx deployment from cluster", func() {
Eventually(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand Down Expand Up @@ -302,7 +302,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {
})

It("publish a resource bundle spec using grpc client", func() {
evt := helper.NewBundleEvent(sourceID, "create_request", consumer.Name, resourceID, deployName, 1, 1)
evt := helper.NewBundleEvent(sourceID, "create_request", agentTestOpts.consumerName, resourceID, deployName, 1, 1)
pbEvt := &pbv1.CloudEvent{}
err := grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt)
Expect(err).To(BeNil(), "failed to convert spec from cloudevent to protobuf")
Expand Down Expand Up @@ -354,7 +354,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {

It("get the nginx deployment from cluster", func() {
Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -374,7 +374,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {
})

It("publish a resource bundle spec with update request using grpc client", func() {
evt := helper.NewBundleEvent(sourceID, "update_request", consumer.Name, resourceID, deployName, 1, 2)
evt := helper.NewBundleEvent(sourceID, "update_request", agentTestOpts.consumerName, resourceID, deployName, 1, 2)
pbEvt := &pbv1.CloudEvent{}
err := grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt)
Expect(err).To(BeNil(), "failed to convert spec from cloudevent to protobuf")
Expand Down Expand Up @@ -426,7 +426,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {

It("get the nginx deployment from cluster", func() {
Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -446,7 +446,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {
})

It("publish a resource bundle spec with delete request using grpc client", func() {
evt := helper.NewBundleEvent(sourceID, "delete_request", consumer.Name, resourceID, deployName, 2, 2)
evt := helper.NewBundleEvent(sourceID, "delete_request", agentTestOpts.consumerName, resourceID, deployName, 2, 2)
pbEvt := &pbv1.CloudEvent{}
err := grpcprotocol.WritePBMessage(ctx, binding.ToMessage(evt), pbEvt)
Expect(err).To(BeNil(), "failed to convert spec from cloudevent to protobuf")
Expand All @@ -470,7 +470,7 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() {

It("get the nginx deployment from cluster", func() {
Eventually(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand Down
52 changes: 26 additions & 26 deletions test/e2e/pkg/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
deployName := fmt.Sprintf("nginx-%s", rand.String(5))
var resource *openapi.Resource
It("post the nginx resource to the maestro api", func() {
res := helper.NewAPIResource(consumer.Name, deployName, 1)
res := helper.NewAPIResource(agentTestOpts.consumerName, deployName, 1)
var resp *http.Response
var err error
resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(ctx).Resource(res).Execute()
Expand All @@ -35,7 +35,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(*resource.Version).To(Equal(int32(1)))

Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -55,15 +55,15 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
})

It("patch the nginx resource with the maestro api", func() {
newRes := helper.NewAPIResource(consumer.Name, deployName, 2)
newRes := helper.NewAPIResource(agentTestOpts.consumerName, deployName, 2)
patchedResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdPatch(ctx, *resource.Id).
ResourcePatchRequest(openapi.ResourcePatchRequest{Version: resource.Version, Manifest: newRes.Manifest}).Execute()
Expect(err).ShouldNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
Expect(*patchedResource.Version).To(Equal(*resource.Version + 1))

Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -80,7 +80,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(resp.StatusCode).To(Equal(http.StatusNoContent))

Eventually(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand All @@ -96,7 +96,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
deployName := fmt.Sprintf("nginx-%s", rand.String(5))
var resource *openapi.Resource
It("post the nginx resource to the maestro api", func() {
res := helper.NewAPIResource(consumer.Name, deployName, 1)
res := helper.NewAPIResource(agentTestOpts.consumerName, deployName, 1)
res.DeleteOption = map[string]interface{}{"propagationPolicy": "Orphan"}
var resp *http.Response
var err error
Expand All @@ -106,7 +106,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(*resource.Id).ShouldNot(BeEmpty())

Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -124,7 +124,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {

// ensure the "nginx" deployment in the "default" namespace is not deleted
Consistently(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return fmt.Errorf("nginx deployment is deleted")
Expand All @@ -135,11 +135,11 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
})

It("delete the nginx deployment", func() {
err := consumer.ClientSet.AppsV1().Deployments("default").Delete(ctx, deployName, metav1.DeleteOptions{})
err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Delete(ctx, deployName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand All @@ -155,7 +155,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
deployName := fmt.Sprintf("nginx-%s", rand.String(5))
var resource *openapi.Resource
It("post the nginx resource to the maestro api with createOnly updateStrategy", func() {
res := helper.NewAPIResource(consumer.Name, deployName, 1)
res := helper.NewAPIResource(agentTestOpts.consumerName, deployName, 1)
res.UpdateStrategy = map[string]interface{}{"type": "CreateOnly"}
var resp *http.Response
var err error
Expand All @@ -165,7 +165,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(*resource.Id).ShouldNot(BeEmpty())

Eventually(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -177,7 +177,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
})

It("patch the nginx resource", func() {
newRes := helper.NewAPIResource(consumer.Name, deployName, 2)
newRes := helper.NewAPIResource(agentTestOpts.consumerName, deployName, 2)
patchedResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdPatch(ctx, *resource.Id).
ResourcePatchRequest(openapi.ResourcePatchRequest{Version: resource.Version, Manifest: newRes.Manifest}).Execute()
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -186,7 +186,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {

// ensure the "nginx" deployment in the "default" namespace is not updated
Consistently(func() error {
deploy, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
deploy, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
return nil
}
Expand All @@ -203,7 +203,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(resp.StatusCode).To(Equal(http.StatusNoContent))

Eventually(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand All @@ -222,21 +222,21 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
nginxDeploy := &appsv1.Deployment{}
err := json.Unmarshal([]byte(helper.NewResourceManifestJSON(deployName, 1)), nginxDeploy)
Expect(err).ShouldNot(HaveOccurred())
_, err = consumer.ClientSet.AppsV1().Deployments("default").Create(ctx, nginxDeploy, metav1.CreateOptions{})
_, err = agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Create(ctx, nginxDeploy, metav1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
})

It("post the resource to the maestro api with readonly updateStrategy", func() {
var resp *http.Response
var err error
// post the resource with readonly updateStrategy and foreground delete option should fail
invalidRes := helper.NewReadOnlyAPIResource(consumer.Name, deployName)
invalidRes := helper.NewReadOnlyAPIResource(agentTestOpts.consumerName, deployName)
invalidRes.DeleteOption = map[string]interface{}{"propagationPolicy": "Foreground"}
resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(ctx).Resource(invalidRes).Execute()
Expect(err).Should(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))

res := helper.NewReadOnlyAPIResource(consumer.Name, deployName)
res := helper.NewReadOnlyAPIResource(agentTestOpts.consumerName, deployName)
resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(ctx).Resource(res).Execute()
Expect(err).ShouldNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusCreated))
Expand Down Expand Up @@ -286,11 +286,11 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusNoContent))

err = consumer.ClientSet.AppsV1().Deployments("default").Delete(ctx, deployName, metav1.DeleteOptions{})
err = agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Delete(ctx, deployName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() error {
_, err := consumer.ClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.AppsV1().Deployments("default").Get(ctx, deployName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand All @@ -307,7 +307,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
secretName := "auth-" + rand.String(5)
manifest := fmt.Sprintf("{\"apiVersion\":\"v1\",\"kind\":\"Secret\",\"metadata\":{\"name\":\"%s\",\"namespace\":\"default\"}}", secretName)
It("create a secret in the target cluster", func() {
_, err := consumer.ClientSet.CoreV1().Secrets("default").Create(ctx, &corev1.Secret{
_, err := agentTestOpts.kubeClientSet.CoreV1().Secrets("default").Create(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: "default",
Expand Down Expand Up @@ -360,7 +360,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
},
}
Eventually(func() error {
_, err := workClient.ManifestWorks(consumer.Name).Create(ctx, work, metav1.CreateOptions{})
_, err := sourceWorkClient.ManifestWorks(agentTestOpts.consumerName).Create(ctx, work, metav1.CreateOptions{})
return err
}, 5*time.Minute, 5*time.Second).ShouldNot(HaveOccurred())
})
Expand All @@ -380,7 +380,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {

It("get the resource status back", func() {
Eventually(func() error {
work, err := workClient.ManifestWorks(consumer.Name).Get(ctx, workName, metav1.GetOptions{})
work, err := sourceWorkClient.ManifestWorks(agentTestOpts.consumerName).Get(ctx, workName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -402,14 +402,14 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
})

It("delete the readonly resource", func() {
err := workClient.ManifestWorks(consumer.Name).Delete(ctx, workName, metav1.DeleteOptions{})
err := sourceWorkClient.ManifestWorks(agentTestOpts.consumerName).Delete(ctx, workName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

err = consumer.ClientSet.CoreV1().Secrets("default").Delete(ctx, secretName, metav1.DeleteOptions{})
err = agentTestOpts.kubeClientSet.CoreV1().Secrets("default").Delete(ctx, secretName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() error {
_, err := consumer.ClientSet.CoreV1().Secrets("default").Get(ctx, secretName, metav1.GetOptions{})
_, err := agentTestOpts.kubeClientSet.CoreV1().Secrets("default").Get(ctx, secretName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand Down
Loading
Loading