minor changes

This commit is contained in:
Zoltan Kiss 2019-10-08 16:39:26 +01:00
parent dc491a2335
commit 00812db89f

View File

@ -13,7 +13,6 @@ import io.fabric8.kubernetes.client.KubernetesClientException
import io.fabric8.kubernetes.client.Watch import io.fabric8.kubernetes.client.Watch
import io.fabric8.kubernetes.client.Watcher import io.fabric8.kubernetes.client.Watcher
import io.fabric8.kubernetes.client.dsl.ExecListener import io.fabric8.kubernetes.client.dsl.ExecListener
import io.fabric8.kubernetes.client.dsl.ExecWatch
import io.fabric8.kubernetes.client.utils.Serialization import io.fabric8.kubernetes.client.utils.Serialization
import net.corda.testing.retry.Retry import net.corda.testing.retry.Retry
import net.corda.testing.retry.Retry.RetryException import net.corda.testing.retry.Retry.RetryException
@ -152,7 +151,7 @@ class KubesTest extends DefaultTask {
int numberOfRetries int numberOfRetries
) { ) {
addShutdownHook { addShutdownHook {
logger.lifecycle("Deleting pod: $podName") logger.lifecycle("deleting pod: $podName")
client.pods().inNamespace(namespace).withName(podName).delete() client.pods().inNamespace(namespace).withName(podName).delete()
} }
@ -170,15 +169,13 @@ class KubesTest extends DefaultTask {
} }
// recreate and run // recreate and run
Pod podRequest = buildPod(podName, pvc)
project.logger.lifecycle("creating pod: $podName") project.logger.lifecycle("creating pod: $podName")
Pod createdPod = client.pods().inNamespace(namespace).create(podRequest) Pod createdPod = client.pods().inNamespace(namespace).create(buildPodRequest(podName, pvc))
project.logger.lifecycle("scheduled pod: $podName") project.logger.lifecycle("scheduled pod: $podName")
attachStatusListenerToPod(client, createdPod) attachStatusListenerToPod(client, createdPod)
waitForPodToStart(client, createdPod) waitForPodToStart(client, createdPod)
File outputFile = Files.createTempFile("container", ".log").toFile()
def stdOutOs = new PipedOutputStream() def stdOutOs = new PipedOutputStream()
def stdOutIs = new PipedInputStream(4096) def stdOutIs = new PipedInputStream(4096)
ByteArrayOutputStream errChannelStream = new ByteArrayOutputStream() ByteArrayOutputStream errChannelStream = new ByteArrayOutputStream()
@ -186,18 +183,16 @@ class KubesTest extends DefaultTask {
CompletableFuture<Integer> waiter = new CompletableFuture<>() CompletableFuture<Integer> waiter = new CompletableFuture<>()
ExecListener execListener = buildExecListenerForPod(podName, errChannelStream, waiter) ExecListener execListener = buildExecListenerForPod(podName, errChannelStream, waiter)
stdOutIs.connect(stdOutOs) stdOutIs.connect(stdOutOs)
ExecWatch execWatch = client.pods().inNamespace(namespace).withName(podName) client.pods().inNamespace(namespace).withName(podName)
.writingOutput(stdOutOs) .writingOutput(stdOutOs)
.writingErrorChannel(errChannelStream) .writingErrorChannel(errChannelStream)
.usingListener(execListener) .usingListener(execListener)
.exec(getBuildCommand(numberOfPods, podIdx)) .exec(getBuildCommand(numberOfPods, podIdx))
startLogPumping(outputFile, stdOutIs, podIdx, printOutput) File outputFile = startLogPumping(stdOutIs, podIdx, printOutput)
int resCode = waiter.join() int resCode = waiter.join()
project.logger.lifecycle("build has ended on on pod ${podName} (${podIdx}/${numberOfPods}), gathering results") project.logger.lifecycle("build has ended on on pod ${podName} (${podIdx}/${numberOfPods}), gathering results")
def binaryResults = downloadTestXmlFromPod(client, namespace, createdPod) def binaryResults = downloadTestXmlFromPod(client, namespace, createdPod)
project.logger.lifecycle("deleting: " + createdPod.getMetadata().getName())
client.pods().delete(createdPod)
return new KubePodResult(resCode, outputFile, binaryResults) return new KubePodResult(resCode, outputFile, binaryResults)
} }
} catch (RetryException e) { } catch (RetryException e) {
@ -205,7 +200,8 @@ class KubesTest extends DefaultTask {
} }
} }
void startLogPumping(File outputFile, stdOutIs, podIdx, boolean printOutput) { File startLogPumping(stdOutIs, podIdx, boolean printOutput) {
File outputFile = Files.createTempFile("container", ".log").toFile()
Thread loggingThread = new Thread({ -> Thread loggingThread = new Thread({ ->
BufferedWriter out = null BufferedWriter out = null
BufferedReader br = null BufferedReader br = null
@ -230,6 +226,7 @@ class KubesTest extends DefaultTask {
loggingThread.setDaemon(true) loggingThread.setDaemon(true)
loggingThread.start() loggingThread.start()
return outputFile
} }
ExecListener buildExecListenerForPod(podName, errChannelStream, CompletableFuture<Integer> waitingFuture) { ExecListener buildExecListenerForPod(podName, errChannelStream, CompletableFuture<Integer> waitingFuture) {
@ -280,7 +277,7 @@ class KubesTest extends DefaultTask {
project.logger.lifecycle("pod " + pod.metadata.name + " has started, executing build") project.logger.lifecycle("pod " + pod.metadata.name + " has started, executing build")
} }
Pod buildPod(String podName, PersistentVolumeClaim pvc) { Pod buildPodRequest(String podName, PersistentVolumeClaim pvc) {
return new PodBuilder().withNewMetadata().withName(podName).endMetadata() return new PodBuilder().withNewMetadata().withName(podName).endMetadata()
.withNewSpec() .withNewSpec()