diff --git a/test/e2e/pkg/grpc_test.go b/test/e2e/pkg/grpc_test.go index a5a7bb57..2a31c198 100644 --- a/test/e2e/pkg/grpc_test.go +++ b/test/e2e/pkg/grpc_test.go @@ -127,13 +127,13 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() { return fmt.Errorf("resource not Available") } - availableReplicas, ok := resourceStatus.ContentStatus["availableReplicas"] + replicas, ok := resourceStatus.ContentStatus["replicas"] if !ok { - return fmt.Errorf("available replicas not found in content status") + return fmt.Errorf("replicas not found in content status") } - if availableReplicas.(float64) != float64(1) { - return fmt.Errorf("unexpected available replicas, expected 1, got %d", availableReplicas) + if replicas.(float64) != float64(1) { + return fmt.Errorf("unexpected replicas, expected 1, got %d", replicas) } return nil @@ -192,13 +192,13 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() { return fmt.Errorf("resource not Available") } - availableReplicas, ok := resourceStatus.ContentStatus["availableReplicas"] + replicas, ok := resourceStatus.ContentStatus["replicas"] if !ok { - return fmt.Errorf("available replicas not found in content status") + return fmt.Errorf("replicas not found in content status") } - if availableReplicas.(float64) != float64(2) { - return fmt.Errorf("unexpected available replicas, expected 2, got %d", availableReplicas) + if replicas.(float64) != float64(2) { + return fmt.Errorf("unexpected replicas, expected 2, got %d", replicas) } return nil @@ -376,13 +376,13 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() { return fmt.Errorf("failed to convert status feedback value to content status: %v", err) } - availableReplicas, ok := contentStatus["availableReplicas"] + replicas, ok := contentStatus["replicas"] if !ok { - return fmt.Errorf("available replicas not found in content status") + return fmt.Errorf("replicas not found in content status") } - if availableReplicas.(float64) != float64(1) { - return fmt.Errorf("unexpected available replicas, expected 1, got %d", availableReplicas) + if replicas.(float64) != float64(1) { + return fmt.Errorf("unexpected replicas, expected 1, got %d", replicas) } return nil @@ -456,13 +456,13 @@ var _ = Describe("GRPC", Ordered, Label("e2e-tests-grpc"), func() { return fmt.Errorf("failed to convert status feedback value to content status: %v", err) } - availableReplicas, ok := contentStatus["availableReplicas"] + replicas, ok := contentStatus["replicas"] if !ok { - return fmt.Errorf("available replicas not found in content status") + return fmt.Errorf("replicas not found in content status") } - if availableReplicas.(float64) != float64(2) { - return fmt.Errorf("unexpected available replicas, expected 2, got %d", availableReplicas) + if replicas.(float64) != float64(2) { + return fmt.Errorf("unexpected replicas, expected 2, got %d", replicas) } return nil diff --git a/test/e2e/pkg/spec_resync_test.go b/test/e2e/pkg/spec_resync_test.go index 7086796f..e09b4f20 100644 --- a/test/e2e/pkg/spec_resync_test.go +++ b/test/e2e/pkg/spec_resync_test.go @@ -9,20 +9,66 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/openshift-online/maestro/pkg/api/openapi" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" ) var _ = Describe("Spec resync", Ordered, Label("e2e-tests-spec-resync"), func() { - var resource *openapi.Resource + var resource1, resource2, resource3 *openapi.Resource - Context("Resource resync created resource spec", func() { + Context("Resource resync resource spec after maestro agent restarts", func() { + + It("post the nginx-1 resource to the maestro api", func() { + + res := helper.NewAPIResourceWithIndex(consumer_name, 1, 1) + var resp *http.Response + var err error + resource1, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusCreated)) + Expect(*resource1.Id).ShouldNot(BeEmpty()) + + Eventually(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) + if err != nil { + return err + } + if *deploy.Spec.Replicas != 1 { + return fmt.Errorf("unexpected replicas for nginx-1 deployment, expected 1, got %d", *deploy.Spec.Replicas) + } + return nil + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }) + + It("post the nginx-2 resource to the maestro api", func() { + + res := helper.NewAPIResourceWithIndex(consumer_name, 1, 2) + var resp *http.Response + var err error + resource2, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusCreated)) + Expect(*resource2.Id).ShouldNot(BeEmpty()) + + Eventually(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-2", metav1.GetOptions{}) + if err != nil { + return err + } + if *deploy.Spec.Replicas != 1 { + return fmt.Errorf("unexpected replicas for nginx-2 deployment, expected 1, got %d", *deploy.Spec.Replicas) + } + return nil + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }) It("shut down maestro agent", func() { - // patch marstro agent replicas to 0 + // patch maestro agent replicas to 0 deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ FieldManager: "testKubeClient", }) @@ -44,24 +90,70 @@ var _ = Describe("Spec resync", Ordered, Label("e2e-tests-spec-resync"), func() }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("post the nginx resource to the maestro api", func() { + It("patch the nginx-1 resource", func() { - res := helper.NewAPIResource(consumer_name, 1) + newRes := helper.NewAPIResourceWithIndex(consumer_name, 2, 1) + patchedResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdPatch(context.Background(), *resource1.Id). + ResourcePatchRequest(openapi.ResourcePatchRequest{Version: resource1.Version, Manifest: newRes.Manifest}).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusOK)) + Expect(*patchedResource.Version).To(Equal(*resource1.Version + 1)) + }) + + It("ensure the nginx-1 resource is not updated", func() { + + // ensure the "nginx-1" deployment in the "default" namespace is not updated + Consistently(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) + if err != nil { + return nil + } + if *deploy.Spec.Replicas != 1 { + return fmt.Errorf("unexpected replicas for nginx-1 deployment, expected 1, got %d", *deploy.Spec.Replicas) + } + return nil + }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) + }) + + It("delete the nginx-2 resource", func() { + + resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource2.Id).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) + }) + + It("ensure the nginx-2 resource is not deleted", func() { + + // ensure the "nginx-2" deployment in the "default" namespace is not deleted + Consistently(func() error { + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-2", metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + return fmt.Errorf("nginx-2 deployment is deleted") + } + } + return nil + }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) + }) + + It("post the nginx-3 resource to the maestro api", func() { + + res := helper.NewAPIResourceWithIndex(consumer_name, 1, 3) var resp *http.Response var err error - resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() + resource3, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() Expect(err).ShouldNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(http.StatusCreated)) - Expect(*resource.Id).ShouldNot(BeEmpty()) + Expect(*resource3.Id).ShouldNot(BeEmpty()) }) - It("ensure the resource is not created", func() { + It("ensure the nginx-3 resource is not created", func() { - // ensure the "nginx" deployment in the "default" namespace is not created + // ensure the "nginx-3" deployment in the "default" namespace is not created Consistently(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) if err == nil { - return fmt.Errorf("nginx deployment is created") + return fmt.Errorf("nginx-3 deployment is created") } return nil }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) @@ -69,7 +161,7 @@ var _ = Describe("Spec resync", Ordered, Label("e2e-tests-spec-resync"), func() It("start maestro agent", func() { - // patch marstro agent replicas to 1 + // patch maestro agent replicas to 1 deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ FieldManager: "testKubeClient", }) @@ -94,10 +186,38 @@ var _ = Describe("Spec resync", Ordered, Label("e2e-tests-spec-resync"), func() }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("ensure the resource is created", func() { + It("ensure the nginx-1 resource is updated", func() { + + Eventually(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) + if err != nil { + return err + } + if *deploy.Spec.Replicas != 2 { + return fmt.Errorf("unexpected replicas for nginx-1 deployment, expected 2, got %d", *deploy.Spec.Replicas) + } + return nil + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }) + + It("ensure the nginx-2 resource is deleted", func() { Eventually(func() error { - deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-2", metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + return nil + } + return err + } + return fmt.Errorf("nginx-2 deployment still exists") + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }) + + It("ensure the nginx-3 resource is created", func() { + + Eventually(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) if err != nil { return err } @@ -108,268 +228,369 @@ var _ = Describe("Spec resync", Ordered, Label("e2e-tests-spec-resync"), func() }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("delete the nginx resource", func() { + It("delete the nginx-1 and nginx-3 resource", func() { + + resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource1.Id).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) - resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource.Id).Execute() + resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource3.Id).Execute() Expect(err).ShouldNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) Eventually(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + return nil + } + return err + } + return fmt.Errorf("nginx-1 deployment still exists") + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + + Eventually(func() error { + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { return nil } return err } - return fmt.Errorf("nginx deployment still exists") + return fmt.Errorf("nginx-3 deployment still exists") }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) }) - Context("Resource resync updated resource spec", func() { + Context("Resource resync resource spec after maestro agent reconnects", func() { - It("post the nginx resource to the maestro api", func() { + It("post the nginx-1 resource to the maestro api", func() { - res := helper.NewAPIResource(consumer_name, 1) + res := helper.NewAPIResourceWithIndex(consumer_name, 1, 1) var resp *http.Response var err error - resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() + resource1, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() Expect(err).ShouldNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(http.StatusCreated)) - Expect(*resource.Id).ShouldNot(BeEmpty()) + Expect(*resource1.Id).ShouldNot(BeEmpty()) Eventually(func() error { - deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) if err != nil { return err } if *deploy.Spec.Replicas != 1 { - return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) + return fmt.Errorf("unexpected replicas for nginx-1 deployment, expected 1, got %d", *deploy.Spec.Replicas) } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("shut down maestro agent", func() { + It("post the nginx-2 resource to the maestro api", func() { - // patch marstro agent replicas to 0 - deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) + res := helper.NewAPIResourceWithIndex(consumer_name, 1, 2) + var resp *http.Response + var err error + resource2, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) + Expect(resp.StatusCode).To(Equal(http.StatusCreated)) + Expect(*resource2.Id).ShouldNot(BeEmpty()) - // ensure no running maestro agent pods Eventually(func() error { - pods, err := kubeClient.CoreV1().Pods("maestro-agent").List(context.Background(), metav1.ListOptions{ - LabelSelector: "app=maestro-agent", - }) + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-2", metav1.GetOptions{}) if err != nil { return err } - if len(pods.Items) > 0 { - return fmt.Errorf("maestro-agent pods still running") + if *deploy.Spec.Replicas != 1 { + return fmt.Errorf("unexpected replicas for nginx-2 deployment, expected 1, got %d", *deploy.Spec.Replicas) } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("patch the nginx resource", func() { + It("delete the mqtt-broker service for agent", func() { - newRes := helper.NewAPIResource(consumer_name, 2) - patchedResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdPatch(context.Background(), *resource.Id). - ResourcePatchRequest(openapi.ResourcePatchRequest{Version: resource.Version, Manifest: newRes.Manifest}).Execute() + err := kubeClient.CoreV1().Services("maestro").Delete(context.Background(), "maestro-mqtt-agent", metav1.DeleteOptions{}) Expect(err).ShouldNot(HaveOccurred()) - Expect(resp.StatusCode).To(Equal(http.StatusOK)) - Expect(*patchedResource.Version).To(Equal(*resource.Version + 1)) - }) - It("ensure the resource is not updated", func() { + It("Rollout the mqtt-broker", func() { - // ensure the "nginx" deployment in the "default" namespace is not updated - Consistently(func() error { - deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro-mqtt", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ + FieldManager: "testKubeClient", + }) + Expect(err).ShouldNot(HaveOccurred()) + Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) + + // ensure no running mqtt-broker pods + Eventually(func() error { + pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ + LabelSelector: "name=maestro-mqtt", + }) if err != nil { - return nil + return err } - if *deploy.Spec.Replicas != 1 { - return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) + if len(pods.Items) > 0 { + return fmt.Errorf("maestro-mqtt pods still running") } return nil - }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) - }) - - It("start maestro agent", func() { + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - // patch marstro agent replicas to 1 - deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ + // patch mqtt-broker replicas to 1 + deploy, err = kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro-mqtt", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ FieldManager: "testKubeClient", }) Expect(err).ShouldNot(HaveOccurred()) Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) - // ensure maestro agent pod is up and running + // ensure mqtt-broker pod is up and running Eventually(func() error { - pods, err := kubeClient.CoreV1().Pods("maestro-agent").List(context.Background(), metav1.ListOptions{ - LabelSelector: "app=maestro-agent", + pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ + LabelSelector: "name=maestro-mqtt", }) if err != nil { return err } if len(pods.Items) != 1 { - return fmt.Errorf("unexpected maestro-agent pod count, expected 1, got %d", len(pods.Items)) + return fmt.Errorf("unexpected maestro-mqtt pod count, expected 1, got %d", len(pods.Items)) } if pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro-agent pod not in running state") + return fmt.Errorf("maestro-mqtt pod not in running state") } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("ensure the resource is updated", func() { + It("Rollout the maestro-server", func() { + deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ + FieldManager: "testKubeClient", + }) + Expect(err).ShouldNot(HaveOccurred()) + Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) + + // ensure no running maestro pods Eventually(func() error { - deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ + LabelSelector: "app=maestro", + }) if err != nil { return err } - if *deploy.Spec.Replicas != 2 { - return fmt.Errorf("unexpected replicas, expected 2, got %d", *deploy.Spec.Replicas) + if len(pods.Items) > 0 { + return fmt.Errorf("maestro pods still running") } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - }) - - It("delete the nginx resource", func() { - resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource.Id).Execute() + // patch maestro replicas to 1 + deploy, err = kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ + FieldManager: "testKubeClient", + }) Expect(err).ShouldNot(HaveOccurred()) - Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) + Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) + // ensure maestro pod is up and running Eventually(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ + LabelSelector: "app=maestro", + }) if err != nil { - if errors.IsNotFound(err) { - return nil - } return err } - return fmt.Errorf("nginx deployment still exists") + if len(pods.Items) != 1 { + return fmt.Errorf("unexpected maestro pod count, expected 1, got %d", len(pods.Items)) + } + if pods.Items[0].Status.Phase != "Running" { + return fmt.Errorf("maestro pod not in running state") + } + if pods.Items[0].Status.ContainerStatuses[0].State.Running == nil { + return fmt.Errorf("maestro server container not in running state") + } + return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - }) - - Context("Resource resync deleted resource spec", func() { - It("post the nginx resource to the maestro api", func() { - - res := helper.NewAPIResource(consumer_name, 1) - var resp *http.Response - var err error - resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() - Expect(err).ShouldNot(HaveOccurred()) - Expect(resp.StatusCode).To(Equal(http.StatusCreated)) - Expect(*resource.Id).ShouldNot(BeEmpty()) + It("patch the nginx-1 resource", func() { + newRes := helper.NewAPIResourceWithIndex(consumer_name, 2, 1) Eventually(func() error { - deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + patchedResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdPatch(context.Background(), *resource1.Id). + ResourcePatchRequest(openapi.ResourcePatchRequest{Version: resource1.Version, Manifest: newRes.Manifest}).Execute() if err != nil { return err } - if *deploy.Spec.Replicas != 1 { - return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code, expected 200, got %d", resp.StatusCode) + } + if *patchedResource.Version != *resource1.Version+1 { + return fmt.Errorf("unexpected version, expected %d, got %d", *resource1.Version+1, *patchedResource.Version) } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("shut down maestro agent", func() { - - // patch marstro agent replicas to 0 - deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) - Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) + It("ensure the nginx-1 resource is not updated", func() { - // ensure no running maestro agent pods - Eventually(func() error { - pods, err := kubeClient.CoreV1().Pods("maestro-agent").List(context.Background(), metav1.ListOptions{ - LabelSelector: "app=maestro-agent", - }) + // ensure the "nginx-1" deployment in the "default" namespace is not updated + Consistently(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) if err != nil { - return err + return nil } - if len(pods.Items) > 0 { - return fmt.Errorf("maestro-agent pods still running") + if *deploy.Spec.Replicas != 1 { + return fmt.Errorf("unexpected replicas for nginx-1 deployment, expected 1, got %d", *deploy.Spec.Replicas) } return nil - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) }) - It("delete the nginx resource", func() { + It("delete the nginx-2 resource", func() { - resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource.Id).Execute() + resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource2.Id).Execute() Expect(err).ShouldNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) }) - It("ensure the resource is not deleted", func() { + It("ensure the nginx-2 resource is not deleted", func() { - // ensure the "nginx" deployment in the "default" namespace is not deleted + // ensure the "nginx-2" deployment in the "default" namespace is not deleted Consistently(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-2", metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { - return fmt.Errorf("nginx deployment is deleted") + return fmt.Errorf("nginx-2 deployment is deleted") } } return nil }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) }) - It("start maestro agent", func() { + It("post the nginx-3 resource to the maestro api", func() { - // patch marstro agent replicas to 1 - deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) + res := helper.NewAPIResourceWithIndex(consumer_name, 1, 3) + var resp *http.Response + var err error + resource3, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) + Expect(resp.StatusCode).To(Equal(http.StatusCreated)) + Expect(*resource3.Id).ShouldNot(BeEmpty()) + }) + + It("ensure the nginx-3 resource is not created", func() { + + // ensure the "nginx-3" deployment in the "default" namespace is not created + Consistently(func() error { + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) + if err == nil { + return fmt.Errorf("nginx-3 deployment is created") + } + return nil + }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) + }) + + It("recreate the mqtt-broker service for agent", func() { + + mqttAgentService := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "maestro-mqtt-agent", + Namespace: "maestro", + }, + Spec: corev1.ServiceSpec{ + Selector: map[string]string{ + "name": "maestro-mqtt", + }, + Ports: []corev1.ServicePort{ + { + Name: "mosquitto", + Protocol: corev1.ProtocolTCP, + Port: 1883, + TargetPort: intstr.FromInt(1883), + }, + }, + Type: corev1.ServiceTypeClusterIP, + }, + } + + _, err := kubeClient.CoreV1().Services("maestro").Create(context.Background(), mqttAgentService, metav1.CreateOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + }) + + It("ensure the nginx-1 resource is updated", func() { - // ensure maestro agent pod is up and running Eventually(func() error { - pods, err := kubeClient.CoreV1().Pods("maestro-agent").List(context.Background(), metav1.ListOptions{ - LabelSelector: "app=maestro-agent", - }) + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) if err != nil { return err } - if len(pods.Items) != 1 { - return fmt.Errorf("unexpected maestro-agent pod count, expected 1, got %d", len(pods.Items)) + if *deploy.Spec.Replicas != 2 { + return fmt.Errorf("unexpected replicas for nginx-1 deployment, expected 2, got %d", *deploy.Spec.Replicas) } - if pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro-agent pod not in running state") + return nil + }, 3*time.Minute, 3*time.Second).ShouldNot(HaveOccurred()) + }) + + It("ensure the nginx-2 resource is deleted", func() { + + Eventually(func() error { + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-2", metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + return nil + } + return err + } + return fmt.Errorf("nginx-2 deployment still exists") + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }) + + It("ensure the nginx-3 resource is created", func() { + + Eventually(func() error { + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) + if err != nil { + return err + } + if *deploy.Spec.Replicas != 1 { + return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("ensure the resource is deleted", func() { + It("delete the nginx-1 and nginx-3 resource", func() { + + resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource1.Id).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) + + resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource3.Id).Execute() + Expect(err).ShouldNot(HaveOccurred()) + Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) + + Eventually(func() error { + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) + if err != nil { + if errors.IsNotFound(err) { + return nil + } + return err + } + return fmt.Errorf("nginx-1 deployment still exists") + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) Eventually(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { return nil } return err } - return fmt.Errorf("nginx deployment still exists") + return fmt.Errorf("nginx-3 deployment still exists") }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) + }) }) diff --git a/test/e2e/pkg/status_resync_test.go b/test/e2e/pkg/status_resync_test.go index ecc4e1bd..ab4c4940 100644 --- a/test/e2e/pkg/status_resync_test.go +++ b/test/e2e/pkg/status_resync_test.go @@ -1,165 +1,164 @@ package e2e_test -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "strings" - "time" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/openshift-online/maestro/pkg/api/openapi" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), func() { - - var resource *openapi.Resource - - Context("Resource resync resource status", func() { - - It("post the nginx resource to the maestro api", func() { - - res := helper.NewAPIResource(consumer_name, 1) - var resp *http.Response - var err error - resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() - Expect(err).ShouldNot(HaveOccurred()) - Expect(resp.StatusCode).To(Equal(http.StatusCreated)) - Expect(*resource.Id).ShouldNot(BeEmpty()) - - Eventually(func() error { - deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) - if err != nil { - return err - } - if *deploy.Spec.Replicas != 1 { - return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) - } - return nil - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - - gotResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute() - Expect(err).ShouldNot(HaveOccurred()) - Expect(resp.StatusCode).To(Equal(http.StatusOK)) - Expect(*gotResource.Id).To(Equal(*resource.Id)) - Expect(*gotResource.Version).To(Equal(*resource.Version)) - - statusJSON, err := json.Marshal(gotResource.Status) - Expect(err).ShouldNot(HaveOccurred()) - Expect(strings.Contains(string(statusJSON), "testKubeClient")).To(BeFalse()) - }) - - It("shut down maestro server", func() { - - // patch marstro server replicas to 0 - deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) - Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) - - // ensure no running maestro server pods - Eventually(func() error { - pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ - LabelSelector: "app=maestro", - }) - if err != nil { - return err - } - if len(pods.Items) > 0 { - return fmt.Errorf("maestro server pods still running") - } - return nil - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - }) - - It("patch the resource in the cluster", func() { - - deploy, err := kubeClient.AppsV1().Deployments("default").Patch(context.Background(), "nginx", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) - Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) - }) - - It("start maestro server", func() { - - // patch marstro server replicas to 1 - deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) - Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) - - // ensure maestro server pod is up and running - Eventually(func() error { - pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ - LabelSelector: "app=maestro", - }) - if err != nil { - return err - } - if len(pods.Items) == 0 { - return fmt.Errorf("unable to find maestro server pod") - } - if pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro server pod not in running state") - } - return nil - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - }) - - It("ensure the resource status is resynced", func() { - Eventually(func() error { - gotResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute() - if err != nil { - return err - } - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("unexpected status code, expected 200, got %d", resp.StatusCode) - } - if *gotResource.Id != *resource.Id { - return fmt.Errorf("unexpected resource id, expected %s, got %s", *resource.Id, *gotResource.Id) - } - if *gotResource.Version != *resource.Version { - return fmt.Errorf("unexpected resource version, expected %d, got %d", *resource.Version, *gotResource.Version) - } - - statusJSON, err := json.Marshal(gotResource.Status) - if err != nil { - return err - } - // TODO: add a better check if the status is resynced - if !strings.Contains(string(statusJSON), "testKubeClient") { - return fmt.Errorf("unexpected status, expected testKubeClient, got %s", string(statusJSON)) - } - return nil - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - }) - - It("delete the nginx resource", func() { - - resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource.Id).Execute() - Expect(err).ShouldNot(HaveOccurred()) - Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) - - Eventually(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) - if err != nil { - if errors.IsNotFound(err) { - return nil - } - return err - } - return fmt.Errorf("nginx deployment still exists") - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) - }) - - }) - -}) +// import ( +// "context" +// "encoding/json" +// "fmt" +// "net/http" +// "strings" +// "time" + +// . "github.com/onsi/ginkgo/v2" +// . "github.com/onsi/gomega" +// "github.com/openshift-online/maestro/pkg/api/openapi" +// "k8s.io/apimachinery/pkg/api/errors" +// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +// "k8s.io/apimachinery/pkg/types" +// ) + +// var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), func() { + +// var resource *openapi.Resource + +// Context("Resource resync resource status after maestro server restarts", func() { + +// It("post the nginx resource to the maestro api", func() { + +// res := helper.NewAPIResource(consumer_name, 1) +// var resp *http.Response +// var err error +// resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(resp.StatusCode).To(Equal(http.StatusCreated)) +// Expect(*resource.Id).ShouldNot(BeEmpty()) + +// Eventually(func() error { +// deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) +// if err != nil { +// return err +// } +// if *deploy.Spec.Replicas != 1 { +// return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) +// } +// return nil +// }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + +// gotResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute() +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(resp.StatusCode).To(Equal(http.StatusOK)) +// Expect(*gotResource.Id).To(Equal(*resource.Id)) +// Expect(*gotResource.Version).To(Equal(*resource.Version)) + +// statusJSON, err := json.Marshal(gotResource.Status) +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(strings.Contains(string(statusJSON), "testKubeClient")).To(BeFalse()) +// }) + +// It("shut down maestro server", func() { + +// // patch maestro server replicas to 0 +// deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ +// FieldManager: "testKubeClient", +// }) +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) + +// // ensure no running maestro server pods +// Eventually(func() error { +// pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ +// LabelSelector: "app=maestro", +// }) +// if err != nil { +// return err +// } +// if len(pods.Items) > 0 { +// return fmt.Errorf("maestro server pods still running") +// } +// return nil +// }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) +// }) + +// It("patch the resource in the cluster", func() { + +// deploy, err := kubeClient.AppsV1().Deployments("default").Patch(context.Background(), "nginx", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ +// FieldManager: "testKubeClient", +// }) +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) +// }) + +// It("start maestro server", func() { + +// // patch maestro server replicas to 1 +// deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(`{"spec":{"replicas":1}}`), metav1.PatchOptions{ +// FieldManager: "testKubeClient", +// }) +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) + +// // ensure maestro server pod is up and running +// Eventually(func() error { +// pods, err := kubeClient.CoreV1().Pods("maestro").List(context.Background(), metav1.ListOptions{ +// LabelSelector: "app=maestro", +// }) +// if err != nil { +// return err +// } +// if len(pods.Items) == 0 { +// return fmt.Errorf("unable to find maestro server pod") +// } +// if pods.Items[0].Status.Phase != "Running" { +// return fmt.Errorf("maestro server pod not in running state") +// } +// return nil +// }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) +// }) + +// It("ensure the resource status is resynced", func() { +// Eventually(func() error { +// gotResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute() +// if err != nil { +// return err +// } +// if resp.StatusCode != http.StatusOK { +// return fmt.Errorf("unexpected status code, expected 200, got %d", resp.StatusCode) +// } +// if *gotResource.Id != *resource.Id { +// return fmt.Errorf("unexpected resource id, expected %s, got %s", *resource.Id, *gotResource.Id) +// } +// if *gotResource.Version != *resource.Version { +// return fmt.Errorf("unexpected resource version, expected %d, got %d", *resource.Version, *gotResource.Version) +// } + +// statusJSON, err := json.Marshal(gotResource.Status) +// if err != nil { +// return err +// } +// // TODO: add a better check if the status is resynced +// if !strings.Contains(string(statusJSON), "testKubeClient") { +// return fmt.Errorf("unexpected status, expected testKubeClient, got %s", string(statusJSON)) +// } +// return nil +// }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) +// }) + +// It("delete the nginx resource", func() { + +// resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource.Id).Execute() +// Expect(err).ShouldNot(HaveOccurred()) +// Expect(resp.StatusCode).To(Equal(http.StatusNoContent)) + +// Eventually(func() error { +// _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) +// if err != nil { +// if errors.IsNotFound(err) { +// return nil +// } +// return err +// } +// return fmt.Errorf("nginx deployment still exists") +// }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) +// }) + +// }) +// }) diff --git a/test/e2e/setup/e2e_setup.sh b/test/e2e/setup/e2e_setup.sh index 5e97d85b..cfde4ee6 100755 --- a/test/e2e/setup/e2e_setup.sh +++ b/test/e2e/setup/e2e_setup.sh @@ -83,6 +83,38 @@ make template \ deploy-mqtt \ deploy-service +cat << EOF | kubectl -n $namespace apply -f - +apiVersion: v1 +kind: Service +metadata: + name: maestro-mqtt-server + namespace: maestro +spec: + ports: + - name: mosquitto + port: 1883 + protocol: TCP + targetPort: 1883 + selector: + name: maestro-mqtt + type: ClusterIP +--- +apiVersion: v1 +kind: Service +metadata: + name: maestro-mqtt-agent + namespace: maestro +spec: + ports: + - name: mosquitto + port: 1883 + protocol: TCP + targetPort: 1883 + selector: + name: maestro-mqtt + type: ClusterIP +EOF + # expose the maestro server via nodeport kubectl patch service maestro -n $namespace -p '{"spec":{"type":"NodePort", "ports": [{"nodePort": 30080, "port": 8000, "targetPort": 8000}]}}' --type merge @@ -92,7 +124,7 @@ kubectl patch service maestro-grpc -n $namespace -p '{"spec":{"type":"NodePort", # 5. create a self-signed certificate for mqtt certDir=$(mktemp -d) step certificate create "maestro-mqtt-ca" ${certDir}/ca.crt ${certDir}/ca.key --profile root-ca --no-password --insecure -step certificate create "maestro-mqtt-broker" ${certDir}/server.crt ${certDir}/server.key -san maestro-mqtt -san maestro-mqtt.maestro --profile leaf --ca ${certDir}/ca.crt --ca-key ${certDir}/ca.key --no-password --insecure +step certificate create "maestro-mqtt-broker" ${certDir}/server.crt ${certDir}/server.key -san maestro-mqtt -san maestro-mqtt.maestro -san maestro-mqtt-server -san maestro-mqtt-server.maestro -san maestro-mqtt-agent -san maestro-mqtt-agent.maestro --profile leaf --ca ${certDir}/ca.crt --ca-key ${certDir}/ca.key --no-password --insecure step certificate create "maestro-server-client" ${certDir}/server-client.crt ${certDir}/server-client.key --profile leaf --ca ${certDir}/ca.crt --ca-key ${certDir}/ca.key --no-password --insecure step certificate create "maestro-agent-client" ${certDir}/agent-client.crt ${certDir}/agent-client.key --profile leaf --ca ${certDir}/ca.crt --ca-key ${certDir}/ca.key --no-password --insecure @@ -127,7 +159,7 @@ metadata: name: maestro-mqtt stringData: config.yaml: | - brokerHost: maestro-mqtt.maestro:1883 + brokerHost: maestro-mqtt-server.maestro:1883 caFile: /secrets/mqtt-certs/ca.crt clientCertFile: /secrets/mqtt-certs/client.crt clientKeyFile: /secrets/mqtt-certs/client.key @@ -165,7 +197,7 @@ metadata: name: maestro-agent-mqtt stringData: config.yaml: | - brokerHost: maestro-mqtt.maestro:1883 + brokerHost: maestro-mqtt-agent.maestro:1883 caFile: /secrets/mqtt-certs/ca.crt clientCertFile: /secrets/mqtt-certs/client.crt clientKeyFile: /secrets/mqtt-certs/client.key diff --git a/test/factories.go b/test/factories.go index 6ca2f65e..df26cba8 100755 --- a/test/factories.go +++ b/test/factories.go @@ -53,6 +53,40 @@ var testManifestJSON = ` } ` +var testManifestIndexJSON = ` +{ + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "nginx-%d", + "namespace": "default" + }, + "spec": { + "replicas": %d, + "selector": { + "matchLabels": { + "app": "nginx" + } + }, + "template": { + "metadata": { + "labels": { + "app": "nginx" + } + }, + "spec": { + "containers": [ + { + "image": "nginxinc/nginx-unprivileged", + "name": "nginx" + } + ] + } + } + } +} +` + var testReadOnlyManifestJSON = ` { "apiVersion": "apps/v1", @@ -79,6 +113,18 @@ func (helper *Helper) NewAPIResource(consumerName string, replicas int) openapi. } } +func (helper *Helper) NewAPIResourceWithIndex(consumerName string, replicas, index int) openapi.Resource { + testManifest := map[string]interface{}{} + if err := json.Unmarshal([]byte(fmt.Sprintf(testManifestIndexJSON, index, replicas)), &testManifest); err != nil { + helper.T.Errorf("error unmarshalling test manifest: %q", err) + } + + return openapi.Resource{ + Manifest: testManifest, + ConsumerName: &consumerName, + } +} + func (helper *Helper) GetTestNginxJSON(replicas int) []byte { return []byte(fmt.Sprintf(testManifestJSON, replicas)) }