Skip to content

Commit

Permalink
Get all during debug
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dhaiducek authored and openshift-merge-bot[bot] committed Mar 12, 2024
1 parent 2461aeb commit e5def51
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/case1_framework_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/case2_config_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
55 changes: 55 additions & 0 deletions test/e2e/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"os/exec"
"slices"
"strings"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -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)
}

0 comments on commit e5def51

Please sign in to comment.