Skip to content

Commit afab52f

Browse files
authored
Stream registry pod logs to standard out (#4385)
1 parent 7f921e7 commit afab52f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

integration-tests/src/test/java/io/apicurio/deployment/RegistryDeploymentManager.java

+27
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.apicurio.deployment;
22

33
import io.fabric8.kubernetes.api.model.Namespace;
4+
import io.fabric8.kubernetes.api.model.PodList;
45
import io.fabric8.kubernetes.client.KubernetesClient;
56
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
67
import io.fabric8.kubernetes.client.LocalPortForward;
8+
import io.fabric8.kubernetes.client.dsl.LogWatch;
79
import io.fabric8.kubernetes.client.dsl.Resource;
810
import io.fabric8.openshift.api.model.Route;
911
import io.fabric8.openshift.client.DefaultOpenShiftClient;
@@ -17,6 +19,7 @@
1719
import java.io.IOException;
1820
import java.io.InputStream;
1921
import java.nio.charset.StandardCharsets;
22+
import java.util.ArrayList;
2023
import java.util.Collection;
2124
import java.util.List;
2225
import java.util.concurrent.CompletableFuture;
@@ -38,6 +41,8 @@ public class RegistryDeploymentManager implements TestExecutionListener {
3841
static KubernetesClient kubernetesClient;
3942
static LocalPortForward registryPortForward;
4043

44+
static List<LogWatch> logWatch;
45+
4146
@Override
4247
public void testPlanExecutionStarted(TestPlan testPlan) {
4348
if (Boolean.parseBoolean(System.getProperty("cluster.tests"))) {
@@ -71,6 +76,10 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
7176
}
7277
}
7378

79+
if (logWatch != null && !logWatch.isEmpty()) {
80+
logWatch.forEach(LogWatch::close);
81+
}
82+
7483
final Resource<Namespace> namespaceResource = kubernetesClient.namespaces()
7584
.withName(TEST_NAMESPACE);
7685
namespaceResource.delete();
@@ -99,12 +108,15 @@ private void handleInfraDeployment() throws Exception {
99108
if (Boolean.parseBoolean(System.getProperty("deployInMemory"))) {
100109
LOGGER.info("Deploying In Memory Registry Variant with image: {} ##################################################", System.getProperty("registry-in-memory-image"));
101110
InMemoryDeploymentManager.deployInMemoryApp(System.getProperty("registry-in-memory-image"));
111+
logWatch = streamPodLogs("apicurio-registry-memory");
102112
} else if (Boolean.parseBoolean(System.getProperty("deploySql"))) {
103113
LOGGER.info("Deploying SQL Registry Variant with image: {} ##################################################", System.getProperty("registry-sql-image"));
104114
SqlDeploymentManager.deploySqlApp(System.getProperty("registry-sql-image"));
115+
logWatch = streamPodLogs("apicurio-registry-sql");
105116
} else if (Boolean.parseBoolean(System.getProperty("deployKafka"))) {
106117
LOGGER.info("Deploying Kafka SQL Registry Variant with image: {} ##################################################", System.getProperty("registry-kafkasql-image"));
107118
KafkaSqlDeploymentManager.deployKafkaApp(System.getProperty("registry-kafkasql-image"));
119+
logWatch = streamPodLogs("apicurio-registry-kafka");
108120
}
109121
}
110122

@@ -180,4 +192,19 @@ private static void deployResource(String resource) {
180192
kubernetesClient.pods()
181193
.inNamespace(TEST_NAMESPACE).waitUntilReady(60, TimeUnit.SECONDS);
182194
}
195+
196+
private static List<LogWatch> streamPodLogs(String container) {
197+
List<LogWatch> logWatchList = new ArrayList<>();
198+
199+
PodList podList = kubernetesClient.pods().inNamespace(TEST_NAMESPACE).withLabel("app", container).list();
200+
201+
podList.getItems().forEach(p -> logWatchList.add(kubernetesClient.pods()
202+
.inNamespace(TEST_NAMESPACE)
203+
.withName(p.getMetadata().getName())
204+
.inContainer(container)
205+
.tailingLines(10)
206+
.watchLog(System.out)));
207+
208+
return logWatchList;
209+
}
183210
}

0 commit comments

Comments
 (0)