diff --git a/testdata/project-v4-multigroup/test/e2e/e2e_test.go b/testdata/project-v4-multigroup/test/e2e/e2e_test.go index 6c32c749e06..743ca527a79 100644 --- a/testdata/project-v4-multigroup/test/e2e/e2e_test.go +++ b/testdata/project-v4-multigroup/test/e2e/e2e_test.go @@ -43,6 +43,8 @@ const metricsServiceName = "project-v4-multigroup-controller-manager-metrics-ser const metricsRoleBindingName = "project-v4-multigroup-metrics-binding" var _ = Describe("Manager", Ordered, func() { + var controllerPodName string + // Before running the tests, set up the environment by creating the namespace, // installing CRDs, and deploying the controller. BeforeAll(func() { @@ -82,12 +84,51 @@ var _ = Describe("Manager", Ordered, func() { _, _ = utils.Run(cmd) }) + AfterEach(func() { + specReport := CurrentSpecReport() + if specReport.Failed() { + By("Fetching controller manager pod logs") + cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace) + controllerLogs, err := utils.Run(cmd) + if err == nil { + fmt.Println("Controller logs:\n", controllerLogs) + } else { + fmt.Println("Failed to get controller logs") + } + + By("Fetching Kubernetes events") + cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp") + eventsOutput, err := utils.Run(cmd) + if err == nil { + fmt.Println("Kubernetes events:\n", eventsOutput) + } else { + fmt.Println("Failed to get Kubernetes events") + } + + By("Fetching curl-metrics logs") + cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace) + metricsOutput, err := utils.Run(cmd) + if err == nil { + fmt.Println("Metrics logs:\n", metricsOutput) + } else { + fmt.Println("Failed to get curl-metrics logs") + } + + By("Fetching controller manager pod description") + cmd = exec.Command("kubectl", "describe", "pod", controllerPodName, "-n", namespace) + podDescription, err := utils.Run(cmd) + if err == nil { + fmt.Println("Pod description:\n", podDescription) + } else { + fmt.Println("Failed to describe controller pod") + } + } + }) + SetDefaultEventuallyTimeout(2 * time.Minute) SetDefaultEventuallyPollingInterval(time.Second) - // The Context block contains the actual tests that validate the manager's behavior. Context("Manager", func() { - var controllerPodName string It("should run successfully", func() { By("validating that the controller-manager pod is running as expected") verifyControllerUp := func(g Gomega) { @@ -108,7 +149,6 @@ var _ = Describe("Manager", Ordered, func() { controllerPodName = podNames[0] g.Expect(controllerPodName).To(ContainSubstring("controller-manager")) - // Validate the pod's status cmd = exec.Command("kubectl", "get", "pods", controllerPodName, "-o", "jsonpath={.status.phase}", "-n", namespace, @@ -117,7 +157,6 @@ var _ = Describe("Manager", Ordered, func() { g.Expect(err).NotTo(HaveOccurred()) g.Expect(string(output)).To(BeEquivalentTo("Running"), "Incorrect controller-manager pod status") } - // Repeatedly check if the controller-manager pod is running until it succeeds or times out. Eventually(verifyControllerUp).Should(Succeed()) })