New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exec_run implementation for containers #126
Conversation
@jwhonce this is the version that is currently seeing the 500 ISE when used in my project. |
podman/domain/containers.py
Outdated
"User": user, | ||
"WorkingDir": workdir | ||
} | ||
response = self.client.post(f"/containers/{self.name}/exec", params=params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacobCallahan Please review https://docs.podman.io/en/latest/_static/api.html#operation/ContainerExecLibpod, name
is the only query parameter you may pass, all the other fields need to be passed as data
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in current update
@jwhonce thanks again for the sage advice! If the object route is the way to go, how would that be done? |
@jwhonce @JacobCallahan what is going on with this PR? |
Unfortunately, I've been dealing with much higher priorities since the last update. Hopefully I'll be able to revisit this soon. One thing that would help with this would be if someone could point out an efficient way to get stdout/stderr from an exec instance container |
@JacobCallahan @jwhonce What should we do with this PR? |
@rhatdan sorry, we have been focusing on other priorities. We're finishing planning for this year and if all goes well, I can revisit this early next month. I believe I left off on how to construct a container object from an exec instance id |
@rhatdan @jwhonce I've revisited this today and have it to the point where it returns the original container object (not the exec container since that seems to be gone by the time the manager can get the object). I don't think this is a very useful return. An output-like object would be better, but I'm not sure how to create that. Any pointers would be appreciated. |
Alright, In the latest version, I have exec_run working with basic commands. However, since it uses entrypoint, it complicates bash-like commands being passed in. In the simple example below, the command executes correctly, the file is created, and we get the correct return code. However, we currently are unable to get any additional relevant information or output from commands. In [4]: ubi8.exec_run("touch test.txt")
{'CanRemove': True, 'ContainerID': 'a260ee5258383680de1189f603f3218a9609ddb664d68d390b5dad58481932af', 'DetachKeys': '', 'ExitCode': 0, 'ID': 'fd37335600af2af4c4f717723eda0fc80ba5767613c1b22b5e3480972179cfab', 'OpenStderr': True, 'OpenStdin': False, 'OpenStdout': True, 'Running': False, 'Pid': 0, 'ProcessConfig': {'arguments': ['test.txt'], 'entrypoint': 'touch', 'privileged': False, 'tty': True, 'user': 'root'}}
Out[4]: 0 |
still cant do exec_run until containers/podman-py#126 but it does everything else.
@JacobCallahan
So it turns your the exec start is blocking whole REST and the end in text we have the output of command. I've tried it with longer commands (sleep for 90seconds and then print whatever and it worked) Example :
Let me know what you think about it |
@msisj Thanks for the fantastic testing! I'm pretty swamped at the moment, but I will definitely check out and try your suggestions. Also, do you think it would be more useful to return the output and exit status in a single object or separate how it is now? I additionally need to consider demuxing the streams. |
@JacobCallahan Returning an object is generally a good idea I suppose, but I'd try to ask any of the owners of this product what interface they want to have honestly. If it comes to demuxing streams I'm wondering why do you need to consider this, is there a planned rework for Podman REST API in this area? To be even more honest, documentation is rather lacking as the exec start basically does not say that it returns any output. |
@JacobCallahan Are you planning to work on this draft? If you don't, I can take some of this code, tweak it and create PR for it (basically I need this feature on master). |
@JacobCallahan @rhatdan Do we have any ETA on this feature? This feature is absolutely critical for our use-case. |
@JacobCallahan Hope you got the chance to revisit this. Thanks in advance. Please share if you have any updates. |
@msisj i had a bit of time to play around with this a bit more today and try out your suggestions. However, I'm still not actually seeing the command output you're seeing. I am only getting back the Id for the exec_start instance.
for reference, the meat of my local version of exec_run # create the exec instance
start_resp = self.client.post(f"/containers/{self.name}/exec", data=json.dumps(data))
start_resp.raise_for_status()
exec_id = start_resp.json()['Id']
# start the exec instance
response = self.client.post(f"/exec/{exec_id}/start", data=json.dumps(
{"Detach": detach, "Tty": tty}
))
response.raise_for_status()
# get and return exec information
response = self.client.get(f"/exec/{exec_id}/json")
response.raise_for_status()
return start_resp.text, response.json().get('ExitCode') |
@JacobCallahan
->
and
->
|
Thanks @msisj @JacobCallahan, That helped.
But I'm having issues with interactive-tty . Below code gets stuck since it's waiting for
Process is getting started inside the container.
Any hints? |
@msisj ahh yep I misunderstood what you meant, thanks for clarifying! The new version is up now and working fine for me. One thing we may want to consider is some kind of parity with Docker's implementation where the response is packaged into a response object with @samarAvi What you would need is an implementation for attach/attach_socket. With that, you could send and read at will. |
Thanks for amazing work so far @JacobCallahan. IMHO attach/attach_socket also needs to be implemented as part of this PR then, could you please take it up. @msisj what do you think? |
@jwhonce thanks. i've switched the return order so the return code is leading. However, I'm getting normal strings back from the API without any additional processing. In order to return bytes, I'd have to explicitly convert it (specifying an encode type like utf-8). If this is something you want, I can certainly add it. In [4]: res = ch.exec_run('hostname')
In [5]: res
Out[5]: (0, '1b122d3312b8\r\n')
In [6]: type(res[1])
Out[6]: str |
@JacobCallahan |
@JacobCallahan For compatibility, I agree with @enhaut you should change to .content from .text. I understand we're pushing the burden to convert to str on most developers, but should the output be binary those will need this type. From reading the documentation and walking code, I think this is it! |
63a5d2b
to
6afc3e6
Compare
@JacobCallahan you need to remove the draft status |
Whats going on with this PR? @rhatdan |
@enhaut Isn't failing a gating test? @JacobCallahan Could you fix this to pass the test? |
356b87d
to
5478a50
Compare
This change adds a basic implementation of exec_run for containers Environment variable conversions are handled from dict->list[str] DetachKeys will need an actual argument option detach, stream, socket, and demux arguments are currently not handled. Signed-off-by: Jacob Callahan <jacob.callahan05@gmail.com>
@rhatdan looks like all automatic checks are passing now |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JacobCallahan, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
LGTM |
/lgtm |
Add exec_run implementation for containers Signed-off-by: Thomas Pohl <thomas.pohl@coherentminds.de>
This change adds a basic implementation of exec_run for containers
Environment variable conversions are handled from dict->list[str]
DetachKeys will need an actual argument option
detach, stream, socket, and demux arguments are currently not handled.