diff --git a/Makefile b/Makefile index d0c0f147..ffb1794e 100755 --- a/Makefile +++ b/Makefile @@ -410,7 +410,7 @@ e2e-test/teardown: .PHONY: e2e-test/teardown e2e-test: e2e-test/teardown e2e-test/setup - ginkgo --output-dir="${PWD}/test/e2e/report" --json-report=report.json --junit-report=report.xml \ + ginkgo -v --output-dir="${PWD}/test/e2e/report" --json-report=report.json --junit-report=report.xml \ ${PWD}/test/e2e/pkg -- -consumer_name=$(shell cat ${PWD}/test/e2e/.consumer_name) \ -api-server=https://$(shell cat ${PWD}/test/e2e/.external_host_ip):30080 \ -grpc-server=$(shell cat ${PWD}/test/e2e/.external_host_ip):30090 \ 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/resources_test.go b/test/e2e/pkg/resources_test.go index 63ab1065..e92c6608 100644 --- a/test/e2e/pkg/resources_test.go +++ b/test/e2e/pkg/resources_test.go @@ -136,7 +136,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() { } } return nil - }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) + }, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred()) }) It("delete the nginx deployment", func() { @@ -199,7 +199,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() { return fmt.Errorf("unexpected replicas, expected 1, got %d", *deploy.Spec.Replicas) } return nil - }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) + }, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred()) }) It("delete the nginx resource", func() { diff --git a/test/e2e/pkg/sourceclient_test.go b/test/e2e/pkg/sourceclient_test.go index 424cc141..5324ac57 100644 --- a/test/e2e/pkg/sourceclient_test.go +++ b/test/e2e/pkg/sourceclient_test.go @@ -9,8 +9,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/openshift-online/maestro/pkg/client/cloudevents/grpcsource" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -20,9 +18,7 @@ import ( workv1 "open-cluster-management.io/api/work/v1" - "open-cluster-management.io/sdk-go/pkg/cloudevents/work" "open-cluster-management.io/sdk-go/pkg/cloudevents/work/common" - "open-cluster-management.io/sdk-go/pkg/cloudevents/work/source/codec" ) var _ = Describe("gRPC Source ManifestWork Client Test", func() { @@ -61,18 +57,18 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() { }) It("The work status should be watched", func() { - workClient, err := work.NewClientHolderBuilder(grpcOptions). - WithClientID(fmt.Sprintf("%s-client", sourceID)). - WithSourceID(sourceID). - WithCodecs(codec.NewManifestBundleCodec()). - WithWorkClientWatcherStore(grpcsource.NewRESTFullAPIWatcherStore(apiClient, sourceID)). - WithResyncEnabled(false). - NewSourceClientHolder(ctx) - Expect(err).ShouldNot(HaveOccurred()) + // workClient, err := work.NewClientHolderBuilder(grpcOptions). + // WithClientID(fmt.Sprintf("%s-client", sourceID)). + // WithSourceID(sourceID). + // WithCodecs(codec.NewManifestBundleCodec()). + // WithWorkClientWatcherStore(grpcsource.NewRESTFullAPIWatcherStore(apiClient, sourceID)). + // WithResyncEnabled(false). + // NewSourceClientHolder(ctx) + // Expect(err).ShouldNot(HaveOccurred()) By("create a work") workName := "work-" + rand.String(5) - _, err = workClient.ManifestWorks(consumer_name).Create(ctx, NewManifestWork(workName), metav1.CreateOptions{}) + _, err := workClient.ManifestWorks(consumer_name).Create(ctx, NewManifestWork(workName), metav1.CreateOptions{}) Expect(err).ShouldNot(HaveOccurred()) // wait for few seconds to ensure the creation is finished diff --git a/test/e2e/pkg/spec_resync_test.go b/test/e2e/pkg/spec_resync_test.go index 7086796f..0fb92dcd 100644 --- a/test/e2e/pkg/spec_resync_test.go +++ b/test/e2e/pkg/spec_resync_test.go @@ -9,21 +9,72 @@ 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 + var mqttReplicas, maestroAgentReplicas int - 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 - deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ + deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Get(context.Background(), "maestro-agent", metav1.GetOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + maestroAgentReplicas = int(*deploy.Spec.Replicas) + + // 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", }) Expect(err).ShouldNot(HaveOccurred()) @@ -44,37 +95,83 @@ 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() { + + 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 + }, 10*time.Second, 1*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() { - res := helper.NewAPIResource(consumer_name, 1) + // 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 + }, 10*time.Second, 1*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()) + }, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred()) }) It("start maestro agent", 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{ + // patch maestro agent replicas to maestroAgentReplicas + deploy, err := kubeClient.AppsV1().Deployments("maestro-agent").Patch(context.Background(), "maestro-agent", types.MergePatchType, []byte(fmt.Sprintf(`{"spec":{"replicas":%d}}`, maestroAgentReplicas)), metav1.PatchOptions{ FieldManager: "testKubeClient", }) Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) + Expect(*deploy.Spec.Replicas).To(Equal(int32(maestroAgentReplicas))) // ensure maestro agent pod is up and running Eventually(func() error { @@ -84,20 +181,53 @@ var _ = Describe("Spec resync", Ordered, Label("e2e-tests-spec-resync"), func() 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 len(pods.Items) != maestroAgentReplicas { + return fmt.Errorf("unexpected maestro-agent pod count, expected %d, got %d", maestroAgentReplicas, len(pods.Items)) + } + for _, pod := range pods.Items { + if pod.Status.Phase != "Running" { + return fmt.Errorf("maestro-agent pod not in running state") + } + if pod.Status.ContainerStatuses[0].State.Running == nil { + return fmt.Errorf("maestro-agent container not in running state") + } + } + return nil + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }) + + 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 pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro-agent pod not in running state") + 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 resource is created", func() { + 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", metav1.GetOptions{}) + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-3", metav1.GetOptions{}) if err != nil { return err } @@ -108,268 +238,327 @@ 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(), *resource.Id).Execute() + 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()) }) }) - 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").Get(context.Background(), "maestro-mqtt", metav1.GetOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + mqttReplicas = int(*deploy.Spec.Replicas) + 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 mqttReplicas + deploy, err = kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro-mqtt", types.MergePatchType, []byte(fmt.Sprintf(`{"spec":{"replicas":%d}}`, mqttReplicas)), metav1.PatchOptions{ FieldManager: "testKubeClient", }) Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) + Expect(*deploy.Spec.Replicas).To(Equal(int32(mqttReplicas))) - // 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)) + if len(pods.Items) != mqttReplicas { + return fmt.Errorf("unexpected maestro-mqtt pod count, expected %d, got %d", mqttReplicas, len(pods.Items)) } - if pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro-agent pod not in running state") + for _, pod := range pods.Items { + if pod.Status.Phase != "Running" { + return fmt.Errorf("maestro-mqtt pod not in running state") + } + if pod.Status.ContainerStatuses[0].State.Running == nil { + return fmt.Errorf("maestro-mqtt container not in running state") + } } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("ensure the resource is updated", func() { + 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 != 2 { - return fmt.Errorf("unexpected replicas, expected 2, 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("delete the nginx resource", func() { + It("ensure the nginx-1 resource is not updated", func() { - resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdDelete(context.Background(), *resource.Id).Execute() + // 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 + }, 10*time.Second, 1*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)) + }) - Eventually(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + 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 nil + return fmt.Errorf("nginx-2 deployment is deleted") } - return err } - return fmt.Errorf("nginx deployment still exists") - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + return nil + }, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred()) }) - }) - Context("Resource resync deleted resource spec", func() { + It("post the nginx-3 resource to the maestro api", func() { - It("post the nginx resource to the maestro api", func() { - - res := helper.NewAPIResource(consumer_name, 1) + 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()) + }) - 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) + 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 - }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + }, 10*time.Second, 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", - }) + 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()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(0))) + }) + + It("ensure the nginx-1 resource is 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", - }) + deploy, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx-1", metav1.GetOptions{}) if err != nil { return err } - if len(pods.Items) > 0 { - return fmt.Errorf("maestro-agent pods still running") + 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("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)) + }, 3*time.Minute, 3*time.Second).ShouldNot(HaveOccurred()) }) - It("ensure the resource is not deleted", func() { + It("ensure the nginx-2 resource is deleted", func() { - // ensure the "nginx" deployment in the "default" namespace is not deleted - Consistently(func() error { - _, err := kubeClient.AppsV1().Deployments("default").Get(context.Background(), "nginx", metav1.GetOptions{}) + Eventually(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 deployment is deleted") + return nil } + return err } - return nil - }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) + return fmt.Errorf("nginx-2 deployment still exists") + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("start maestro agent", func() { + It("ensure the nginx-3 resource is created", 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", - }) - Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) - - // 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-3", 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 pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro-agent pod not in running state") + 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..8943a22e 100644 --- a/test/e2e/pkg/status_resync_test.go +++ b/test/e2e/pkg/status_resync_test.go @@ -11,6 +11,7 @@ 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" @@ -19,12 +20,13 @@ import ( var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), func() { var resource *openapi.Resource + var maestroServerReplicas int - Context("Resource resync resource status", func() { + Context("Resource resync resource status after maestro server restarts", func() { - It("post the nginx resource to the maestro api", func() { + It("post the nginx resource with non-default service account to the maestro api", func() { - res := helper.NewAPIResource(consumer_name, 1) + res := helper.NewAPIResourceWithSA(consumer_name, 1, "nginx") var resp *http.Response var err error resource, resp, err = apiClient.DefaultApi.ApiMaestroV1ResourcesPost(context.Background()).Resource(res).Execute() @@ -49,15 +51,30 @@ var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), fun 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()) + Eventually(func() error { + gotResource, _, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute() + if err != nil { + return err + } + statusJSON, err := json.Marshal(gotResource.Status) + if err != nil { + return err + } + if !strings.Contains(string(statusJSON), "error looking up service account default/nginx") { + return fmt.Errorf("unexpected status, expected error looking up service account default/nginx, got %s", string(statusJSON)) + } + return nil + }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) 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{ + deploy, err := kubeClient.AppsV1().Deployments("maestro").Get(context.Background(), "maestro", metav1.GetOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + maestroServerReplicas = int(*deploy.Spec.Replicas) + + // 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()) @@ -78,23 +95,28 @@ var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), fun }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) }) - It("patch the resource in the cluster", func() { + It("create default/nginx serviceaccount", func() { - deploy, err := kubeClient.AppsV1().Deployments("default").Patch(context.Background(), "nginx", types.MergePatchType, []byte(`{"spec":{"replicas":0}}`), metav1.PatchOptions{ - FieldManager: "testKubeClient", - }) + _, err := kubeClient.CoreV1().ServiceAccounts("default").Create(context.Background(), &corev1.ServiceAccount{ + ObjectMeta: metav1.ObjectMeta{ + Name: "nginx", + }, + }, metav1.CreateOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + + // delete the nginx deployment to tigger recreating + err = kubeClient.AppsV1().Deployments("default").Delete(context.Background(), "nginx", metav1.DeleteOptions{}) 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{ + // patch maestro server replicas to 1 + deploy, err := kubeClient.AppsV1().Deployments("maestro").Patch(context.Background(), "maestro", types.MergePatchType, []byte(fmt.Sprintf(`{"spec":{"replicas":%d}}`, maestroServerReplicas)), metav1.PatchOptions{ FieldManager: "testKubeClient", }) Expect(err).ShouldNot(HaveOccurred()) - Expect(*deploy.Spec.Replicas).To(Equal(int32(1))) + Expect(*deploy.Spec.Replicas).To(Equal(int32(maestroServerReplicas))) // ensure maestro server pod is up and running Eventually(func() error { @@ -104,39 +126,37 @@ var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), fun if err != nil { return err } - if len(pods.Items) == 0 { - return fmt.Errorf("unable to find maestro server pod") + if len(pods.Items) != maestroServerReplicas { + return fmt.Errorf("unexpected maestro server pod count, expected %d, got %d", maestroServerReplicas, len(pods.Items)) } - if pods.Items[0].Status.Phase != "Running" { - return fmt.Errorf("maestro server pod not in running state") + for _, pod := range pods.Items { + if pod.Status.Phase != "Running" { + return fmt.Errorf("maestro server pod not in running state") + } + if pod.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()) }) It("ensure the resource status is resynced", func() { + Eventually(func() error { - gotResource, resp, err := apiClient.DefaultApi.ApiMaestroV1ResourcesIdGet(context.Background(), *resource.Id).Execute() + gotResource, _, 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 _, ok := gotResource.Status["ContentStatus"]; !ok { + return fmt.Errorf("unexpected status, expected contains ContentStatus, got %v", gotResource.Status) } - 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)) + if strings.Contains(string(statusJSON), "error looking up service account default/nginx") { + return fmt.Errorf("unexpected status, should not contain error looking up service account default/nginx, got %s", string(statusJSON)) } return nil }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) @@ -158,8 +178,10 @@ var _ = Describe("Status resync", Ordered, Label("e2e-tests-status-resync"), fun } return fmt.Errorf("nginx deployment still exists") }, 1*time.Minute, 1*time.Second).ShouldNot(HaveOccurred()) + + err = kubeClient.CoreV1().ServiceAccounts("default").Delete(context.Background(), "nginx", metav1.DeleteOptions{}) + Expect(err).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..20d9e1ea 100755 --- a/test/factories.go +++ b/test/factories.go @@ -53,6 +53,75 @@ var testManifestJSON = ` } ` +var testManifestJSONWithSA = ` +{ + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "name": "nginx", + "namespace": "default" + }, + "spec": { + "replicas": %d, + "selector": { + "matchLabels": { + "app": "nginx" + } + }, + "template": { + "metadata": { + "labels": { + "app": "nginx" + } + }, + "spec": { + "serviceAccount": "%s", + "containers": [ + { + "image": "nginxinc/nginx-unprivileged", + "name": "nginx" + } + ] + } + } + } +} +` + +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 +148,30 @@ func (helper *Helper) NewAPIResource(consumerName string, replicas int) openapi. } } +func (helper *Helper) NewAPIResourceWithSA(consumerName string, replicas int, sa string) openapi.Resource { + testManifest := map[string]interface{}{} + if err := json.Unmarshal([]byte(fmt.Sprintf(testManifestJSONWithSA, replicas, sa)), &testManifest); err != nil { + helper.T.Errorf("error unmarshalling test manifest: %q", err) + } + + return openapi.Resource{ + Manifest: testManifest, + ConsumerName: &consumerName, + } +} + +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)) }