From 92c070f408f84ac2ac53374890419cdfa5389e4f Mon Sep 17 00:00:00 2001 From: Gabriele Quaresima Date: Mon, 14 Oct 2024 16:15:37 +0200 Subject: [PATCH] fix: e2e and conflict after rebase Signed-off-by: Gabriele Quaresima --- internal/cmd/manager/instance/run/cmd.go | 4 +- tests/e2e/declarative_pub_sub_test.go | 110 ++++++++---------- .../destination-cluster.yaml.template | 2 + 3 files changed, 50 insertions(+), 66 deletions(-) diff --git a/internal/cmd/manager/instance/run/cmd.go b/internal/cmd/manager/instance/run/cmd.go index bd6958aecc..07cd1fea0c 100644 --- a/internal/cmd/manager/instance/run/cmd.go +++ b/internal/cmd/manager/instance/run/cmd.go @@ -231,7 +231,7 @@ func runSubCommand(ctx context.Context, instance *postgres.Instance) error { For(&apiv1.Publication{}). Complete(publicationReconciler) if err != nil { - setupLog.Error(err, "unable to create publication controller") + contextLogger.Error(err, "unable to create publication controller") return err } @@ -241,7 +241,7 @@ func runSubCommand(ctx context.Context, instance *postgres.Instance) error { For(&apiv1.Subscription{}). Complete(subscriptionReconciler) if err != nil { - setupLog.Error(err, "unable to create subscription controller") + contextLogger.Error(err, "unable to create subscription controller") return err } diff --git a/tests/e2e/declarative_pub_sub_test.go b/tests/e2e/declarative_pub_sub_test.go index 760d32515d..5965171b9d 100644 --- a/tests/e2e/declarative_pub_sub_test.go +++ b/tests/e2e/declarative_pub_sub_test.go @@ -86,20 +86,6 @@ var _ = Describe("Declarative publication and subscription test", Label(tests.La }) }) - assertDatabaseExists := func(namespace, primaryPod, dbname string) { - Eventually(func(g Gomega) { - stdout, _, err := env.ExecQueryInInstancePod( - utils.PodLocator{ - Namespace: namespace, - PodName: primaryPod, - }, - "postgres", - "\\l") - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(stdout).Should(ContainSubstring(dbname)) - }, 300).Should(Succeed()) - } - assertPublicationExists := func(namespace, primaryPod string, pub *apiv1.Publication) { query := fmt.Sprintf("select count(*) from pg_publication where pubname = '%s'", pub.Spec.Name) @@ -132,7 +118,7 @@ var _ = Describe("Declarative publication and subscription test", Label(tests.La }, 30).Should(Succeed()) } - It("can add a declarative database", func() { //nolint:dupl + It("can add a declarative database, publication and subscription", func() { //nolint:dupl By("applying Database CRD manifest", func() { CreateResourceFromFile(namespace, databaseManifest) databaseObjectName, err = env.GetResourceNameFromYAML(databaseManifest) @@ -157,64 +143,60 @@ var _ = Describe("Declarative publication and subscription test", Label(tests.La primaryPodInfo, err := env.GetClusterPrimary(namespace, sourceClusterName) Expect(err).ToNot(HaveOccurred()) - assertDatabaseExists(namespace, primaryPodInfo.Name, dbname) + AssertDatabaseExists(namespace, primaryPodInfo.Name, dbname, true) }) }) - It("can add a declarative publication", func() { //nolint:dupl - By("applying Publication CRD manifest", func() { - CreateResourceFromFile(namespace, pubManifest) - pubObjectName, err = env.GetResourceNameFromYAML(pubManifest) - Expect(err).NotTo(HaveOccurred()) - }) - By("ensuring the Publication CRD succeeded reconciliation", func() { - // get publication object - pub = &apiv1.Publication{} - pubNamespacedName := types.NamespacedName{ - Namespace: namespace, - Name: pubObjectName, - } - - Eventually(func(g Gomega) { - err := env.Client.Get(env.Ctx, pubNamespacedName, pub) - Expect(err).ToNot(HaveOccurred()) - g.Expect(pub.Status.Ready).Should(BeTrue()) - }, 300).WithPolling(10 * time.Second).Should(Succeed()) - }) + By("applying Publication CRD manifest", func() { + CreateResourceFromFile(namespace, pubManifest) + pubObjectName, err = env.GetResourceNameFromYAML(pubManifest) + Expect(err).NotTo(HaveOccurred()) + }) + By("ensuring the Publication CRD succeeded reconciliation", func() { + // get publication object + pub = &apiv1.Publication{} + pubNamespacedName := types.NamespacedName{ + Namespace: namespace, + Name: pubObjectName, + } - By("verifying new publication has been created", func() { - primaryPodInfo, err := env.GetClusterPrimary(namespace, sourceClusterName) + Eventually(func(g Gomega) { + err := env.Client.Get(env.Ctx, pubNamespacedName, pub) Expect(err).ToNot(HaveOccurred()) - - assertPublicationExists(namespace, primaryPodInfo.Name, pub) - }) + g.Expect(pub.Status.Ready).Should(BeTrue()) + }, 300).WithPolling(10 * time.Second).Should(Succeed()) }) - It("can add a declarative subscription", func() { //nolint:dupl - By("applying Subscription CRD manifest", func() { - CreateResourceFromFile(namespace, subManifest) - subObjectName, err = env.GetResourceNameFromYAML(subManifest) - Expect(err).NotTo(HaveOccurred()) - }) - By("ensuring the Subscription CRD succeeded reconciliation", func() { - // get subscription object - sub = &apiv1.Subscription{} - pubNamespacedName := types.NamespacedName{ - Namespace: namespace, - Name: subObjectName, - } - Eventually(func(g Gomega) { - err := env.Client.Get(env.Ctx, pubNamespacedName, sub) - Expect(err).ToNot(HaveOccurred()) - g.Expect(sub.Status.Ready).Should(BeTrue()) - }, 300).WithPolling(10 * time.Second).Should(Succeed()) - }) + By("verifying new publication has been created", func() { + primaryPodInfo, err := env.GetClusterPrimary(namespace, sourceClusterName) + Expect(err).ToNot(HaveOccurred()) + + assertPublicationExists(namespace, primaryPodInfo.Name, pub) + }) + By("applying Subscription CRD manifest", func() { + CreateResourceFromFile(namespace, subManifest) + subObjectName, err = env.GetResourceNameFromYAML(subManifest) + Expect(err).NotTo(HaveOccurred()) + }) + By("ensuring the Subscription CRD succeeded reconciliation", func() { + // get subscription object + sub = &apiv1.Subscription{} + pubNamespacedName := types.NamespacedName{ + Namespace: namespace, + Name: subObjectName, + } - By("verifying new subscription has been created", func() { - primaryPodInfo, err := env.GetClusterPrimary(namespace, destinationClusterName) + Eventually(func(g Gomega) { + err := env.Client.Get(env.Ctx, pubNamespacedName, sub) Expect(err).ToNot(HaveOccurred()) + g.Expect(sub.Status.Ready).Should(BeTrue()) + }, 300).WithPolling(10 * time.Second).Should(Succeed()) + }) - assertSubscriptionExists(namespace, primaryPodInfo.Name, sub) - }) + By("verifying new subscription has been created", func() { + primaryPodInfo, err := env.GetClusterPrimary(namespace, destinationClusterName) + Expect(err).ToNot(HaveOccurred()) + + assertSubscriptionExists(namespace, primaryPodInfo.Name, sub) }) }) }) diff --git a/tests/e2e/fixtures/declarative_pub_sub/destination-cluster.yaml.template b/tests/e2e/fixtures/declarative_pub_sub/destination-cluster.yaml.template index b8e7531abe..a0be6258e7 100644 --- a/tests/e2e/fixtures/declarative_pub_sub/destination-cluster.yaml.template +++ b/tests/e2e/fixtures/declarative_pub_sub/destination-cluster.yaml.template @@ -4,6 +4,8 @@ metadata: name: destination-cluster spec: instances: 3 + externalClusters: + - name: source-cluster postgresql: parameters: