From 573e262a39bc33c331617debcda13e2ddc9be2a1 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Tue, 23 Jan 2024 12:27:07 +0100 Subject: [PATCH] Collect also deployment.yaml when test fails Signed-off-by: David Kornel --- .../odh/test/framework/logs/LogCollector.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/io/odh/test/framework/logs/LogCollector.java b/src/main/java/io/odh/test/framework/logs/LogCollector.java index 729e7e6e..e7f9f7f2 100644 --- a/src/main/java/io/odh/test/framework/logs/LogCollector.java +++ b/src/main/java/io/odh/test/framework/logs/LogCollector.java @@ -5,6 +5,7 @@ package io.odh.test.framework.logs; import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.apps.Deployment; import io.odh.test.Environment; import io.odh.test.OdhConstants; import io.odh.test.TestConstants; @@ -78,6 +79,22 @@ private static void writePodsDescription(Path logpath, Pod pod) { } } + private static void writeDeployments(Path logpath, Deployment deployment) { + try { + Files.createDirectories(logpath.resolve(deployment.getMetadata().getNamespace())); + } catch (IOException e) { + LOGGER.warn("Cannot create logdir in {}", logpath); + } + try { + LOGGER.debug("Get deployment {}/{}", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName()); + Files.writeString(logpath.resolve(deployment.getMetadata().getNamespace()).resolve("deployment-" + deployment.getMetadata().getName() + ".yaml"), + ResourceManager.getKubeCmdClient().exec(false, false, "get", "deployment", deployment.getMetadata().getName(), + "-n", deployment.getMetadata().getNamespace(), "-o", "yaml").out()); + } catch (IOException e) { + LOGGER.warn("Cannot get deployment of pod {}/{}", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName()); + } + } + private static void saveClusterState(Path logpath) throws IOException { KubeClient kube = ResourceManager.getClient(); KubeCmdClient cmdClient = ResourceManager.getKubeCmdClient(); @@ -99,6 +116,8 @@ private static void saveClusterState(Path logpath) throws IOException { writeLogsFromPods(logpath, pod); writePodsDescription(logpath, pod); }); + LOGGER.debug("Listing deployments in {}", ns.getMetadata().getName()); + kube.getClient().apps().deployments().inNamespace(ns.getMetadata().getName()).list().getItems().forEach(d -> writeDeployments(logpath, d)); }); } }