-
Notifications
You must be signed in to change notification settings - Fork 41
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
adopt playground containers #200
Conversation
@@ -56,6 +59,33 @@ export class PlayGroundManager { | |||
this.queries = new Map<number, QueryState>(); | |||
} | |||
|
|||
async adoptRunningPlaygrounds() { | |||
const containers = await containerEngine.listContainers(); |
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.
@benoitf this call returns an empty list when the extension is loaded at startup (and the correct list of containers when the extension is reloaded, after podman desktop has finished initialization).
What would be the right way to wait for the container engine to be up and running?
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.
We need to materialize the connection from AI studio to podman machine at a central point I'm pretty sure there is some code that try to get this connection
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.
I'm finally using provider.onDidRegisterContainerConnection
to get informed.
2e4db4a
to
44c74bb
Compare
@@ -60,6 +64,43 @@ export class PlayGroundManager { | |||
this.queries = new Map<number, QueryState>(); | |||
} | |||
|
|||
async adoptRunningPlaygrounds() { | |||
provider.onDidRegisterContainerConnection(async (e: RegisterContainerConnectionEvent) => { |
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.
Isn't the register method only called when you create a new connection? (e.g when you create a new podman machine?) Could we use the onDidUpdateContainerConnection
so it also listens to machines that were stopped and now get started?
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.
The moment I'm trying to detect is when podman desktop starts and initializes the extensions. At this moment, the podman extension will register itself as container provider, and this is what I want to be informed.
I tried onDidUpdateContainerConnection but it is not triggered at startup.
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.
I think what we need is a ConnectionProvider within AI Studio. As startup, it should get the first available Podman connection and then listen for connection changes. Every other piece of AI Studio should use this connection provider to get a Podman connection.
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.
Please look at my latest commit, it should do what you describe
5a75fda
to
76beff3
Compare
init(): void { | ||
// In case the extension has not yet registered, we listen for new registrations | ||
// and retain the first started podman provider | ||
const disposable = provider.onDidRegisterContainerConnection((e: RegisterContainerConnectionEvent) => { |
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.
Why are we listening on connection registration andnot connection start/stop events ?
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.
For this feature, I only want to list containers started before Podman Desktop is started, and I want to be informed when the podman extension is registered (or the listContainers
would return an empty list if we try to retrieve the list before).
(note that there is a registries/ContainerRegistry
which is watching at events on a specific container, which we may merge with this class at some point)
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.
I didn't test it so maybe i'm wrong but looking at the code it looks to me that it initializes the connection when the studio is activated if there is atleast one podman machine that is started and then it starts listening to if a machine gets registered.
So if i start my desktop having my podman machine stopped, the connection is not set as there is no podman machine running. If i start my podman machine in a second moment it does not trigger its initialization bc it only listen to machine registration.
So if i start the playground or any other feature that requires to retrieve the active connection it fails, no? But i have my podman machine running fine, i just started it after my desktop was activated
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.
Yes, you are probably right, I'll look at supporting this scenario too. Thanks
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.
Finally, I prefer for now to remove this exposure and use of connection
from the PodmcnConnection
class, as it is not part of what is needed to fix the targeted issue, which is only related to getting a connection to the provider at startup.
I'll work at this refactoring as part of another PR, if necessary.
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.
Here is a demo on Linux to see what you can test:
adopt-playground-2024-02-02_10.29.49.mp4
My other scenario is, you are using the playground, turn off the machine bc you switch to another or whatever. ai-studio should be able to remove the adopted container as it is stopped now, then you turn the machine on again, the container is there stopped, yo start it, ai-studio should be able to adopt it again.
For now, we are not checking when a machine is stopped, to mark playground as stopped. It would be an extension of the PR #194 (and not particularly part of this PR as it is a different logic).
As said in my previous message, when you stop a playground container, it is also deleted (because marked as AUTOREMOVE). So you will never have a playground container (not even stopped) when you start a podman machine.
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.
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.
AFAIK, it is not the expected behaviour for a container marked as auto-removable. In Inspect of this container, is it marked as this?
"HostConfig": {
[...]
"AutoRemove": true,
I'm doing the same test in my Windows machine, and the container is not present anymore
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.
Not that I don't want to support these stopped containers, but if we consider having stopped playground containers, this adds a third state for the playground container in the UI (paused in addition to not-running and running), which we would also have to manage in the UI (set the playground in pause, etc). That would be a bigger change than just detecting a stopped container is started again.
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.
Sorry for the slow response. Done it again now and i confirm that the Autoremove flag is there
76beff3
to
2ebd657
Compare
Co-authored-by: axel7083 <[email protected]>
2ebd657
to
286cef4
Compare
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.
Tested and works fine for this specific use case
fix up renaming of IMAGE Constants.
This PR adds a new class
PodmanConnection
, whose instance listens for new/updated 'podman' container providers, so other managers can get informed of new containers and adopt some of them depending on their labels.It is used as part of this PR for adopting playground containers.
It is expected to be used to detect and adopt recipe pods in a future PR.
Fixes #57