Skip to content

Commit

Permalink
Collect also deployment.yaml when test fails
Browse files Browse the repository at this point in the history
Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys committed Jan 23, 2024
1 parent 68df859 commit 573e262
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/io/odh/test/framework/logs/LogCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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));
});
}
}

0 comments on commit 573e262

Please sign in to comment.