1
1
package io .apicurio .deployment ;
2
2
3
3
import io .fabric8 .kubernetes .api .model .Namespace ;
4
+ import io .fabric8 .kubernetes .api .model .PodList ;
4
5
import io .fabric8 .kubernetes .client .KubernetesClient ;
5
6
import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
6
7
import io .fabric8 .kubernetes .client .LocalPortForward ;
8
+ import io .fabric8 .kubernetes .client .dsl .LogWatch ;
7
9
import io .fabric8 .kubernetes .client .dsl .Resource ;
8
10
import io .fabric8 .openshift .api .model .Route ;
9
11
import io .fabric8 .openshift .client .DefaultOpenShiftClient ;
17
19
import java .io .IOException ;
18
20
import java .io .InputStream ;
19
21
import java .nio .charset .StandardCharsets ;
22
+ import java .util .ArrayList ;
20
23
import java .util .Collection ;
21
24
import java .util .List ;
22
25
import java .util .concurrent .CompletableFuture ;
@@ -38,6 +41,8 @@ public class RegistryDeploymentManager implements TestExecutionListener {
38
41
static KubernetesClient kubernetesClient ;
39
42
static LocalPortForward registryPortForward ;
40
43
44
+ static List <LogWatch > logWatch ;
45
+
41
46
@ Override
42
47
public void testPlanExecutionStarted (TestPlan testPlan ) {
43
48
if (Boolean .parseBoolean (System .getProperty ("cluster.tests" ))) {
@@ -71,6 +76,10 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
71
76
}
72
77
}
73
78
79
+ if (logWatch != null && !logWatch .isEmpty ()) {
80
+ logWatch .forEach (LogWatch ::close );
81
+ }
82
+
74
83
final Resource <Namespace > namespaceResource = kubernetesClient .namespaces ()
75
84
.withName (TEST_NAMESPACE );
76
85
namespaceResource .delete ();
@@ -99,12 +108,15 @@ private void handleInfraDeployment() throws Exception {
99
108
if (Boolean .parseBoolean (System .getProperty ("deployInMemory" ))) {
100
109
LOGGER .info ("Deploying In Memory Registry Variant with image: {} ##################################################" , System .getProperty ("registry-in-memory-image" ));
101
110
InMemoryDeploymentManager .deployInMemoryApp (System .getProperty ("registry-in-memory-image" ));
111
+ logWatch = streamPodLogs ("apicurio-registry-memory" );
102
112
} else if (Boolean .parseBoolean (System .getProperty ("deploySql" ))) {
103
113
LOGGER .info ("Deploying SQL Registry Variant with image: {} ##################################################" , System .getProperty ("registry-sql-image" ));
104
114
SqlDeploymentManager .deploySqlApp (System .getProperty ("registry-sql-image" ));
115
+ logWatch = streamPodLogs ("apicurio-registry-sql" );
105
116
} else if (Boolean .parseBoolean (System .getProperty ("deployKafka" ))) {
106
117
LOGGER .info ("Deploying Kafka SQL Registry Variant with image: {} ##################################################" , System .getProperty ("registry-kafkasql-image" ));
107
118
KafkaSqlDeploymentManager .deployKafkaApp (System .getProperty ("registry-kafkasql-image" ));
119
+ logWatch = streamPodLogs ("apicurio-registry-kafka" );
108
120
}
109
121
}
110
122
@@ -180,4 +192,19 @@ private static void deployResource(String resource) {
180
192
kubernetesClient .pods ()
181
193
.inNamespace (TEST_NAMESPACE ).waitUntilReady (60 , TimeUnit .SECONDS );
182
194
}
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
+ }
183
210
}
0 commit comments