From e5def518d4d970d847fca0d364962caa252d3451 Mon Sep 17 00:00:00 2001 From: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:20:19 -0500 Subject: [PATCH] Get all during debug Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> Add debug logging to E2E Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> --- Makefile | 8 +-- test/e2e/case1_framework_deployment_test.go | 4 ++ test/e2e/case2_config_deployment_test.go | 4 ++ test/e2e/utils_test.go | 55 +++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2ae4a213..7ee55570 100644 --- a/Makefile +++ b/Makefile @@ -269,11 +269,11 @@ e2e-stop-instrumented: .PHONY: e2e-debug e2e-debug: ## Collect debug logs from deployed clusters. @echo "##### Gathering information from $(KIND_NAME) #####" + -KUBECONFIG=$(KIND_KUBECONFIG) kubectl get managedclusters -KUBECONFIG=$(KIND_KUBECONFIG) kubectl get managedclusteraddons --all-namespaces - -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n $(CONTROLLER_NAMESPACE) get deployments - -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n $(CONTROLLER_NAMESPACE) get pods - -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n open-cluster-management-agent-addon get deployments - -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n open-cluster-management-agent-addon get pods + -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n $(CONTROLLER_NAMESPACE) get all + -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n open-cluster-management-agent get all + -KUBECONFIG=$(KIND_KUBECONFIG) kubectl -n open-cluster-management-agent-addon get all -KUBECONFIG=$(KIND_KUBECONFIG) kubectl get manifestwork --all-namespaces -o yaml @echo "* Local controller log:" diff --git a/test/e2e/case1_framework_deployment_test.go b/test/e2e/case1_framework_deployment_test.go index 6f0da73e..eec0a4d2 100644 --- a/test/e2e/case1_framework_deployment_test.go +++ b/test/e2e/case1_framework_deployment_test.go @@ -35,6 +35,10 @@ var _ = Describe("Test framework deployment", Ordered, func() { }) AfterAll(func() { + if CurrentSpecReport().Failed() { + debugCollection(case1PodSelector) + } + By("Deleting the default governance-policy-framework ClusterManagementAddon from the hub cluster") Kubectl("delete", "-f", case1ClusterManagementAddOnCRDefault) }) diff --git a/test/e2e/case2_config_deployment_test.go b/test/e2e/case2_config_deployment_test.go index 5a0c2fd5..9b9b8278 100644 --- a/test/e2e/case2_config_deployment_test.go +++ b/test/e2e/case2_config_deployment_test.go @@ -94,6 +94,10 @@ var _ = Describe("Test config-policy-controller deployment", Ordered, func() { }) AfterAll(func() { + if CurrentSpecReport().Failed() { + debugCollection(case2PodSelector) + } + By("Deleting the default config-policy-controller ClusterManagementAddon from the hub cluster") Kubectl("delete", "-f", case2ClusterManagementAddOnCRDefault) }) diff --git a/test/e2e/utils_test.go b/test/e2e/utils_test.go index 51ad2c58..6775a50e 100644 --- a/test/e2e/utils_test.go +++ b/test/e2e/utils_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os/exec" + "slices" "strings" . "github.com/onsi/ginkgo/v2" @@ -179,3 +180,57 @@ func getAddonStatus(addon *unstructured.Unstructured) bool { return false } + +func debugCollection(podSelector string) { + namespaceSuffix := []string{""} + + if slices.Contains(CurrentSpecReport().Labels(), "hosted-mode") { + namespaceSuffix = append(namespaceSuffix, "-hosted") + } + + By("Recording debug logs") + + output := "===\n" + + for i, cluster := range managedClusterList { + targetKubeconfig := fmt.Sprintf("--kubeconfig=%s%d_e2e", kubeconfigFilename, i+1) + targetCluster := cluster.clusterName + clusterNs := []string{cluster.clusterName} + + if cluster.clusterName == "cluster1" { + for _, cluster := range managedClusterList[1:] { + clusterNs = append(clusterNs, cluster.clusterName) + } + } + + for _, namespace := range clusterNs { + for _, suffix := range namespaceSuffix { + namespace += suffix + output += fmt.Sprintf("Cluster %s: All objects in namespace %s:\n", targetCluster, namespace) + output += Kubectl("get", "all", "-n", namespace, targetKubeconfig) + output += "===\n" + output += fmt.Sprintf( + "Cluster %s: Pod logs for label %s in namespace %s:\n", + targetCluster, podSelector, namespace, + ) + output += Kubectl("describe", "pod", "-n", namespace, "-l", podSelector, targetKubeconfig) + output += Kubectl("logs", "-n", namespace, "-l", podSelector, "--ignore-errors", targetKubeconfig) + output += "===\n" + } + } + + output += fmt.Sprintf("Cluster %s: All objects in namespace %s:\n", targetCluster, addonNamespace) + output += Kubectl("get", "all", "-n", addonNamespace, targetKubeconfig) + output += "===\n" + output += fmt.Sprintf("Cluster %s: Pod logs for label %s in namespace %s for cluster %s:\n", + targetCluster, podSelector, addonNamespace, cluster.clusterName) + output += Kubectl( + "describe", "pod", "-n", addonNamespace, "-l", podSelector, targetKubeconfig, + ) + output += Kubectl( + "logs", "-n", addonNamespace, "-l", podSelector, "--ignore-errors", targetKubeconfig, + ) + } + + GinkgoWriter.Print(output) +}