Package io.kubernetes.client
Class Exec
java.lang.Object
io.kubernetes.client.Exec
- Direct Known Subclasses:
Copy
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExecute a command in a container.Execute a command in a container.exec
(io.kubernetes.client.openapi.models.V1Pod pod, String[] command, String container, boolean stdin, boolean tty) Execute a command in a container.Execute a command in a container.Execute a command in a container.Execute a command in a container.exec
(String namespace, String podName, Consumer<io.kubernetes.client.custom.IOTrio> onOpen, BiConsumer<Integer, io.kubernetes.client.custom.IOTrio> onClosed, BiConsumer<Throwable, io.kubernetes.client.custom.IOTrio> onError, Long timeoutMs, boolean tty, String... command) A convenience method.io.kubernetes.client.openapi.ApiClient
Get the API client for these exec operations.newExecutionBuilder
(String namespace, String name, String[] command) Setup a Builder for the given namespace, name and commandprotected void
void
setApiClient
(io.kubernetes.client.openapi.ApiClient apiClient) Set the API client for subsequent exec operations.void
setOnUnhandledError
(Consumer<Throwable> onUnhandledError)
-
Constructor Details
-
Exec
public Exec()Simple Exec API constructor, uses default configuration -
Exec
public Exec(io.kubernetes.client.openapi.ApiClient apiClient) Exec API Constructor- Parameters:
apiClient
- The api client to use.
-
-
Method Details
-
getApiClient
public io.kubernetes.client.openapi.ApiClient getApiClient()Get the API client for these exec operations.- Returns:
- The API client that will be used.
-
setApiClient
public void setApiClient(io.kubernetes.client.openapi.ApiClient apiClient) Set the API client for subsequent exec operations.- Parameters:
apiClient
- The new API client to use.
-
getOnUnhandledError
-
setOnUnhandledError
-
newExecutionBuilder
Setup a Builder for the given namespace, name and command- Parameters:
namespace
- The namespace of the Podname
- The name of the Podcommand
- The command to run
-
exec
public Process exec(String namespace, String name, String[] command, boolean stdin) throws io.kubernetes.client.openapi.ApiException, IOException Execute a command in a container. If there are multiple containers in the pod, uses the first container in the Pod.- Parameters:
namespace
- The namespace of the Podname
- The name of the Podcommand
- The command to runstdin
- If true, pass a stdin stream into the container- Throws:
io.kubernetes.client.openapi.ApiException
IOException
-
exec
public Process exec(io.kubernetes.client.openapi.models.V1Pod pod, String[] command, boolean stdin) throws io.kubernetes.client.openapi.ApiException, IOException Execute a command in a container. If there are multiple containers in the pod, uses the first container in the Pod.- Parameters:
pod
- The pod where the command is run.command
- The command to runstdin
- If true, pass a stdin stream into the container- Throws:
io.kubernetes.client.openapi.ApiException
IOException
-
exec
public Process exec(String namespace, String name, String[] command, boolean stdin, boolean tty) throws io.kubernetes.client.openapi.ApiException, IOException Execute a command in a container. If there are multiple containers in the pod, uses the first container in the Pod.- Parameters:
namespace
- The namespace of the Podname
- The name of the Podcommand
- The command to runstdin
- If true, pass a stdin stream into the containertty
- If true, stdin is a tty.- Throws:
io.kubernetes.client.openapi.ApiException
IOException
-
exec
public Process exec(io.kubernetes.client.openapi.models.V1Pod pod, String[] command, boolean stdin, boolean tty) throws io.kubernetes.client.openapi.ApiException, IOException Execute a command in a container. If there are multiple containers in the pod, uses the first container in the Pod.- Parameters:
pod
- The pod where the command is run.command
- The command to runstdin
- If true, pass a stdin stream into the containertty
- If true, stdin is a tty.- Throws:
io.kubernetes.client.openapi.ApiException
IOException
-
exec
public Process exec(io.kubernetes.client.openapi.models.V1Pod pod, String[] command, String container, boolean stdin, boolean tty) throws io.kubernetes.client.openapi.ApiException, IOException Execute a command in a container. If there are multiple containers in the pod, uses the first container in the Pod.- Parameters:
pod
- The pod where the command is run.command
- The command to runcontainer
- The container in the Pod where the command is run.stdin
- If true, pass a stdin stream into the container.tty
- If true, stdin is a TTY (only applies if stdin is true)- Throws:
io.kubernetes.client.openapi.ApiException
IOException
-
exec
public Process exec(String namespace, String name, String[] command, String container, boolean stdin, boolean tty) throws io.kubernetes.client.openapi.ApiException, IOException Execute a command in a container. If there are multiple containers in the pod, uses the first container in the Pod.- Parameters:
namespace
- The namespace of the Podname
- The name of the Podcommand
- The command to runcontainer
- The container in the Pod where the command is run.stdin
- If true, pass a stdin stream into the container.tty
- If true, stdin is a TTY (only applies if stdin is true)- Throws:
io.kubernetes.client.openapi.ApiException
IOException
-
exec
public Future<Integer> exec(String namespace, String podName, Consumer<io.kubernetes.client.custom.IOTrio> onOpen, BiConsumer<Integer, io.kubernetes.client.custom.IOTrio> onClosed, BiConsumer<Throwable, throws IOExceptionio.kubernetes.client.custom.IOTrio> onError, Long timeoutMs, boolean tty, String... command) A convenience method. Executes a command remotely on a pod and monitors for events in that execution. The monitored events are:
- connection established (onOpen)
- connection closed (onClosed)
- execution error occurred (onError)
This method also allows to specify a MAX timeout for the execution and returns a future in order to monitor the execution flow.
onError and onClosed callbacks are invoked asynchronously, in a separate thread.- Parameters:
namespace
- a namespace the target pod "lives" inpodName
- a name of the pod to exec the command ononOpen
- a callback invoked upon the connection established event.onClosed
- a callback invoked upon the process termination. Return code might not always be there. N.B. this callback is invoked before the returnedFuture
is completed.onError
- a callback to handle k8s errors (NOT the command errors/stderr!)timeoutMs
- timeout in milliseconds for the execution. I.e. the execution will take this many ms or less. If the timeout command is running longer than the allowed timeout, the command will be "asked" to terminate gracefully. If the command is still running after the grace period, the sigkill will be issued. If null is passed, the timeout will not be used and will wait for process to exit itself.tty
- whether you need tty to pipe the data. TTY mode will trim some binary data in order to make it possible to show on screen (tty)command
- a tokenized command to run on the pod- Returns:
- a
Future
promise representing this execution. Unless something goes south, the promise will contain the process return exit code. If the timeoutMs is non-null and the timeout expires before the process exits, promise will containInteger.MAX_VALUE
. - Throws:
IOException
-
runAsync
-