Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.charset.Charset;
import java.util.Arrays;

import static com.dajudge.kindcontainer.Utils.prefixLines;
import static java.lang.String.join;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down Expand Up @@ -53,6 +54,8 @@ public ExecResult execInContainer(final Charset outputCharset, final String... c
protected void safeExecInContainer(final String... cmd) throws IOException, InterruptedException, ExecutionException {
LOG.info("Executing command: {}", join(" ", Arrays.asList(cmd)));
final ExecResult result = execInContainer(cmd);
LOG.trace("{}", prefixLines(result.getStdout(), "STDOUT: "));
LOG.trace("{}", prefixLines(result.getStderr(), "STDERR: "));
if (result.getExitCode() != 0) {
throw new ExecutionException(cmd, result);
}
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/dajudge/kindcontainer/KindContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void kubeadmInit(final Map<String, String> params) throws IOException, I
));
} catch (final RuntimeException | IOException | InterruptedException e) {
try {
LOG.error("{}", prefixLines(execInContainer("journalctl").getStdout(), "JOURNAL: "));
LOG.error("{}", Utils.prefixLines(execInContainer("journalctl").getStdout(), "JOURNAL: "));
} catch (final IOException | InterruptedException ex) {
LOG.error("Could not retrieve journal.", ex);
}
Expand Down Expand Up @@ -271,12 +271,12 @@ private void exec(final List<String> exec) throws IOException, InterruptedExcept
final int exitCode = execResult.getExitCode();
if (exitCode == 0) {
LOG.debug("\"{}\" exited with status code {}", cmdString, exitCode);
LOG.debug("{}", prefixLines(execResult.getStdout(), "STDOUT: "));
LOG.debug("{}", prefixLines(execResult.getStderr(), "STDERR: "));
LOG.debug("{}", Utils.prefixLines(execResult.getStdout(), "STDOUT: "));
LOG.debug("{}", Utils.prefixLines(execResult.getStderr(), "STDERR: "));
} else {
LOG.error("\"{}\" exited with status code {}", cmdString, exitCode);
LOG.error("{}", prefixLines(execResult.getStdout(), "STDOUT: "));
LOG.error("{}", prefixLines(execResult.getStderr(), "STDERR: "));
LOG.error("{}", Utils.prefixLines(execResult.getStdout(), "STDOUT: "));
LOG.error("{}", Utils.prefixLines(execResult.getStderr(), "STDERR: "));
throw new IllegalStateException(cmdString + " exited with status code " + execResult);
}
}
Expand Down Expand Up @@ -440,8 +440,4 @@ public String toString() {
return format("%d.%d.%d", descriptor.getMajor(), descriptor.getMinor(), descriptor.getPatch());
}
}

private static String prefixLines(String stdout, String prefix) {
return stdout.replaceAll("(?m)^", prefix);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/dajudge/kindcontainer/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ static Network.NetworkImpl createNetwork() {
.build();
}

static String prefixLines(final String strings, final String prefix) {
return strings.replaceAll("(?m)^", prefix);
}

public interface ThrowingRunnable<E extends Exception> {
void run() throws E;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/dajudge/kindcontainer/Helm3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.junit.ClassRule;
import org.junit.Test;

import static com.dajudge.kindcontainer.TestUtils.runWithClient;
import static org.junit.Assert.assertFalse;

public class Helm3Test {

@ClassRule
Expand All @@ -18,5 +21,8 @@ public class Helm3Test {

@Test
public void can_install_something() {
runWithClient(K8S, client -> {
assertFalse(client.apps().deployments().inNamespace("kubernetes-replicator").list().getItems().isEmpty());
});
}
}