-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rework pod_exec example Rework this example to be closer to the one provided by the official kubernetes python api. The busybox pod is now created if it does not exist, making the example easier to use. Also, use contexts to ensure resources are properly released. This prepares the work for next commits that will add more cases in this pod_exec example. Signed-off-by: Olivier Matz <[email protected]> * introduce helper to get command return code in ws_client When the websocket API is used to execute a command on a pod, the status is sent over the ERROR_CHANNEL on termination. Add a helper to parse this information that returns the exit code of the command. This helper can only be used if _preload_content=False. The pod_exec example will be updated in next commit to make use of this new helper. Signed-off-by: Olivier Matz <[email protected]> * add an interactive case in pod_exec example Introduce an example that shows how the WsApiClient can be used to interactively execute a command on a pod. The example is similar to what is done in the official kubernetes python api. Signed-off-by: Olivier Matz <[email protected]> * remove extra await when calling ws_connect() The ClientSession.ws_connect() method is synchronous and returns a _RequestContextManager which takes a coroutine as parameter (here, ClientSession._ws_connect()). This context manager is in charge of closing the connection in its __aexit__() method, so it has to be used with "async with". However, this context manager can also be awaited as it has an __await__() method. In this case, it will await the _ws_connect() coroutine. This is what is done in the current code, but the connection will not be released. Remove the "await" to return the context manager, so that the user can use it with "async with", which will properly release resources. This is the documented way of using ws_connect(): https://docs.aiohttp.org/en/stable/client_quickstart.html#websockets Signed-off-by: Olivier Matz <[email protected]> --------- Signed-off-by: Olivier Matz <[email protected]>
- Loading branch information
1 parent
2126b1d
commit a37f664
Showing
3 changed files
with
157 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters