This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new 168b66036c fix problem where k8s logs are sometimes reset
168b66036c is described below
commit 168b66036cc973af7a3f015c757c03460ad9310c
Author: Alex Heneveld <[email protected]>
AuthorDate: Wed Jul 20 15:30:40 2022 +0100
fix problem where k8s logs are sometimes reset
---
.../brooklyn/tasks/kubectl/ContainerTaskFactory.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git
a/software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java
b/software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java
index d9736f61a4..bab7b06fcb 100644
---
a/software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java
+++
b/software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java
@@ -319,9 +319,17 @@ public class ContainerTaskFactory<T extends
ContainerTaskFactory<T,RET>,RET> imp
throw new IllegalStateException("Error
detected with container job while reading logs (exit code
"+outputSoFarCmd.getExitCode()+"): "+outputSoFarCmd.getStdout() + " /
"+outputSoFarCmd.getStderr());
}
String outputSoFar = outputSoFarCmd.get();
- String newOutput =
outputSoFar.substring(stdout.size());
- LOG.debug("Container job "+namespace+"
output: "+newOutput);
-
stdout.write(newOutput.getBytes(StandardCharsets.UTF_8));
+ int bytesAlreadyRead = stdout.size();
+ if (bytesAlreadyRead <=
outputSoFar.length()) {
+ String newOutput =
outputSoFar.substring(stdout.size());
+ LOG.debug("Container job " + namespace
+ " output: " + newOutput);
+
stdout.write(newOutput.getBytes(StandardCharsets.UTF_8));
+ } else {
+ // not sure why this happens, but it
does sometimes; for now just reset
+ LOG.debug("Container job " + namespace
+ " output reset, length "+outputSoFar.length()+" less than
"+bytesAlreadyRead+"; ignoring new output:\n" + outputSoFar +"\n"+new
String(stdout.toByteArray()));
+ stdout.reset();
+
stdout.write(outputSoFar.getBytes(StandardCharsets.UTF_8));
+ }
if (timer.isExpired())
throw new
IllegalStateException("Timeout waiting for success or failure");