LIRAN Y
11/15/2022, 4:29 PMfun execIntoContainer(podName: String, containerId: String, cmd: String) : String {
val future = CompletableFuture<Int>()
val listener = CompletableExecListener(future)
val out = ByteArrayOutputStream()
val error = ByteArrayOutputStream()
val command = cmd.split(" ").toTypedArray()
val exec = kubernetesClient.pods().withName(podName).inContainer(containerId)
.writingOutput(out)
.writingError(error)
.usingListener(listener)
.exec(*command)
future.get(10, TimeUnit.SECONDS)
exec.close()
if (error.toString().isEmpty()) {
return out.toString()
}
throw RuntimeException("Error from pod: $error")
}
it seems works just for one command.
when i add a grep for example (ls -ltr | grep t) it gave me an error and seems like the issue is with the split part
cmd.split(" ").toTypedArray()
org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.RuntimeException: Error from pod: ls: cannot access '|': No such file or directory
ls: cannot access 'grep': No such file or directory
ls: cannot access 't': No such file or directory
any idea how can i use the split?Sam
11/15/2022, 4:41 PMexec
a shell and pass your command to it. e.g.
val command = arrayOf("/bin/sh", "-c", cmd)
LIRAN Y
11/15/2022, 4:53 PM