From 4f3e3457594f38f24df0186ee827985273baf0f5 Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Wed, 17 Sep 2025 18:06:26 +0200 Subject: [PATCH 1/2] ci(nightly): Also display Operator logs at the end of the E2E tests This is to help with troubleshooting potential SeaLights issues --- tests/e2e/e2e_suite_test.go | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index c43a0e054..fe794b10b 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -24,6 +24,7 @@ const ( defaultDeployTestMode = "" ) +var _start time.Time var _namespace = "rhdh-operator" var testMode = os.Getenv("BACKSTAGE_OPERATOR_TEST_MODE") var managerPodLabel = "app=rhdh-operator" @@ -183,6 +184,7 @@ func installOperatorWithMakeDeploy(withOlm bool) { } var _ = SynchronizedBeforeSuite(func() []byte { + _start = time.Now() //runs *only* on process #1 fmt.Fprintln(GinkgoWriter, "isOpenshift:", helper.IsOpenShift()) @@ -215,11 +217,13 @@ var _ = SynchronizedAfterSuite(func() { //runs on *all* processes }, // the function below *only* on process #1 - uninstallOperator, + func() { + defer uninstallOperator() + fmt.Println(fetchOperatorLogs(managerPodLabel, false)()) + }, ) -func verifyControllerUp(g Gomega, managerPodLabel string) { - // Get pod name +func getControllerPodName() (string, error) { cmd := exec.Command(helper.GetPlatformTool(), "get", "pods", "-l", managerPodLabel, "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}"+ @@ -227,14 +231,22 @@ func verifyControllerUp(g Gomega, managerPodLabel string) { "-n", _namespace, ) podOutput, err := helper.Run(cmd) - g.Expect(err).ShouldNot(HaveOccurred()) + if err != nil { + return "", err + } podNames := helper.GetNonEmptyLines(string(podOutput)) - g.Expect(podNames).Should(HaveLen(1), fmt.Sprintf("expected 1 controller pods running, but got %d", len(podNames))) - controllerPodName := podNames[0] - g.Expect(controllerPodName).ShouldNot(BeEmpty()) + if len(podNames) == 0 { + return "", fmt.Errorf("no pods found") + } + return podNames[0], nil +} + +func verifyControllerUp(g Gomega, managerPodLabel string) { + controllerPodName, err := getControllerPodName() + g.Expect(err).ShouldNot(HaveOccurred()) // Validate pod status - cmd = exec.Command(helper.GetPlatformTool(), "get", + cmd := exec.Command(helper.GetPlatformTool(), "get", "pods", controllerPodName, "-o", "jsonpath={.status.phase}", "-n", _namespace, ) @@ -243,8 +255,19 @@ func verifyControllerUp(g Gomega, managerPodLabel string) { g.Expect(string(status)).Should(Equal("Running"), fmt.Sprintf("controller pod in %s status", status)) } -func getPodLogs(ns string, label string) string { - cmd := exec.Command(helper.GetPlatformTool(), "logs", "--all-containers", "-l", label, "-n", ns) +func getPodLogs(ns string, podName string, label string) string { + opts := []string{ + "-n", ns, + "logs", + "--all-containers", + "--since-time", _start.Format(time.RFC3339), + } + if podName != "" { + opts = append(opts, podName) + } else if label != "" { + opts = append(opts, "-l", label) + } + cmd := exec.Command(helper.GetPlatformTool(), opts...) output, _ := helper.Run(cmd) return string(output) } @@ -257,7 +280,13 @@ func describePod(ns string, label string) string { func fetchOperatorLogs(managerPodLabel string, raw bool) func() string { return func() string { - logs := getPodLogs(_namespace, managerPodLabel) + var logs string + controllerPodName, err := getControllerPodName() + if err != nil { + logs = fmt.Sprintf("Failed to get controller pod name: %v", err) + } else { + logs = getPodLogs(_namespace, controllerPodName, managerPodLabel) + } if raw { return logs } @@ -267,7 +296,7 @@ func fetchOperatorLogs(managerPodLabel string, raw bool) func() string { func fetchOperandLogs(ns string, crLabel string, raw bool) func() string { return func() string { - logs := getPodLogs(ns, crLabel) + logs := getPodLogs(ns, "", crLabel) if raw { return logs } From 66f3d54ed1def5d18075d2c547d648ef81c6c49a Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Wed, 17 Sep 2025 18:09:49 +0200 Subject: [PATCH 2/2] Update tests/e2e/e2e_suite_test.go --- tests/e2e/e2e_suite_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index fe794b10b..00ca90921 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -184,8 +184,8 @@ func installOperatorWithMakeDeploy(withOlm bool) { } var _ = SynchronizedBeforeSuite(func() []byte { - _start = time.Now() //runs *only* on process #1 + _start = time.Now() fmt.Fprintln(GinkgoWriter, "isOpenshift:", helper.IsOpenShift()) if operatorManifest := os.Getenv("OPERATOR_MANIFEST"); operatorManifest != "" {