ExecWatch exec = client.pods().withName(containerId).writingOutput(baos).writingError(baos).usingListener(new ExecListener() {
/** * Copy some files by executing a tar command to the stdout and return the InputStream that contains the tar * contents. * <p> * Unfortunately due to the fact that any error handling happens on another thread, if the tar command fails the * InputStream will simply be empty and it will close. It won't propagate an Exception to the reader of the * InputStream. */ @Override public InputStream copyFiles(String containerId, String folderName) { ByteArrayOutputStream stderr = new ByteArrayOutputStream(); String[] command = new String[] { "tar", "-C", folderName, "-c", "." }; CopyFilesExecListener listener = new CopyFilesExecListener(stderr, command, containerId); ExecWatch exec = client.pods().withName(containerId).redirectingOutput().writingError(stderr).usingListener(listener).exec(command); // FIXME: This is a bit dodgy, but we need the listener to be able to close the ExecWatch in failure conditions, // because it doesn't cleanup properly and deadlocks. // Needs bugs fixed inside kubernetes-client. listener.setExecWatch(exec); // When zalenium is under high load sometimes the stdout isn't connected by the time we try to read from it. // Let's wait until it is connected before proceeding. listener.waitForInputStreamToConnect(); return exec.getOutput(); }
public static void main(String[] args) throws InterruptedException { if (args.length < 1) { System.out.println("Usage: podName [master] [namespace]"); return; } String podName = args[0]; String namespace = "default"; String master = "https://localhost:8443/"; if (args.length > 1) { master = args[1]; } if (args.length > 2) { namespace = args[2]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config); ExecWatch watch = client.pods().inNamespace(namespace).withName(podName) .readingInput(System.in) .writingOutput(System.out) .writingError(System.err) .withTTY() .usingListener(new SimpleListener()) .exec()){ Thread.sleep(10 * 1000); } }
.redirectingInput() .writingOutput(out) .writingError(out) .withTTY() .usingListener(new ExecListener() {
.redirectingInput().writingOutput(stream).writingError(stream).writingErrorChannel(error) .usingListener(new ExecListener() { @Override