Skip to content

Commit ecca3e5

Browse files
test
1 parent 366efdb commit ecca3e5

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

testdata/project-v4-multigroup/test/e2e/e2e_test.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const metricsServiceName = "project-v4-multigroup-controller-manager-metrics-ser
4343
const metricsRoleBindingName = "project-v4-multigroup-metrics-binding"
4444

4545
var _ = Describe("Manager", Ordered, func() {
46+
var controllerPodName string
47+
4648
// Before running the tests, set up the environment by creating the namespace,
4749
// installing CRDs, and deploying the controller.
4850
BeforeAll(func() {
@@ -82,12 +84,51 @@ var _ = Describe("Manager", Ordered, func() {
8284
_, _ = utils.Run(cmd)
8385
})
8486

87+
AfterEach(func() {
88+
specReport := CurrentSpecReport()
89+
if specReport.Failed() {
90+
By("Fetching controller manager pod logs")
91+
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
92+
controllerLogs, err := utils.Run(cmd)
93+
if err == nil {
94+
fmt.Println("Controller logs:\n", controllerLogs)
95+
} else {
96+
fmt.Println("Failed to get controller logs")
97+
}
98+
99+
By("Fetching Kubernetes events")
100+
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
101+
eventsOutput, err := utils.Run(cmd)
102+
if err == nil {
103+
fmt.Println("Kubernetes events:\n", eventsOutput)
104+
} else {
105+
fmt.Println("Failed to get Kubernetes events")
106+
}
107+
108+
By("Fetching curl-metrics logs")
109+
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
110+
metricsOutput, err := utils.Run(cmd)
111+
if err == nil {
112+
fmt.Println("Metrics logs:\n", metricsOutput)
113+
} else {
114+
fmt.Println("Failed to get curl-metrics logs")
115+
}
116+
117+
By("Fetching controller manager pod description")
118+
cmd = exec.Command("kubectl", "describe", "pod", controllerPodName, "-n", namespace)
119+
podDescription, err := utils.Run(cmd)
120+
if err == nil {
121+
fmt.Println("Pod description:\n", podDescription)
122+
} else {
123+
fmt.Println("Failed to describe controller pod")
124+
}
125+
}
126+
})
127+
85128
SetDefaultEventuallyTimeout(2 * time.Minute)
86129
SetDefaultEventuallyPollingInterval(time.Second)
87130

88-
// The Context block contains the actual tests that validate the manager's behavior.
89131
Context("Manager", func() {
90-
var controllerPodName string
91132
It("should run successfully", func() {
92133
By("validating that the controller-manager pod is running as expected")
93134
verifyControllerUp := func(g Gomega) {
@@ -108,7 +149,6 @@ var _ = Describe("Manager", Ordered, func() {
108149
controllerPodName = podNames[0]
109150
g.Expect(controllerPodName).To(ContainSubstring("controller-manager"))
110151

111-
// Validate the pod's status
112152
cmd = exec.Command("kubectl", "get",
113153
"pods", controllerPodName, "-o", "jsonpath={.status.phase}",
114154
"-n", namespace,
@@ -117,7 +157,6 @@ var _ = Describe("Manager", Ordered, func() {
117157
g.Expect(err).NotTo(HaveOccurred())
118158
g.Expect(string(output)).To(BeEquivalentTo("Running"), "Incorrect controller-manager pod status")
119159
}
120-
// Repeatedly check if the controller-manager pod is running until it succeeds or times out.
121160
Eventually(verifyControllerUp).Should(Succeed())
122161
})
123162

0 commit comments

Comments
 (0)