-
Notifications
You must be signed in to change notification settings - Fork 293
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
feat: add podman extension api package and use it in podman extension #8891
base: main
Are you sure you want to change the base?
Conversation
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.
missing unit tests
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 it might help if we're able to remove the code from other extensions using dedicated podman code
Here it seems we're assuming other extensions are using the CLI when calling 'podman stuff' but for example Ai-Lab is using the API, not the CLI to a lot of code.
so the API should provide a way to get all the podman connections as well directly
could be interesting that to have PR in other repositories to see if the API will fit, before trying to provide an API that extensions won't consume/solve the problem.
export interface PodmanExtensionApi { | ||
exec(args: string[], options?: RunOptions): Promise<RunResult>; | ||
} |
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 I don't see how consumers will be able to use that API in case of multiple providers (applehv, libkrun)
For example I see an hardcoded 'podman' value in the implementation:
return execPodman(args, 'podman', options);
but if I look at execPodman method
export function execPodman(
args: string[],
containersProvider?: string,
options?: extensionApi.RunOptions,
): Promise<extensionApi.RunResult> {
containersProvider is an option to specify like is it Apple Hypervisor, is it libkrun, etc.
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 we should pass the object ProviderContainerConnection
or ContainerProviderConnection
instead of a string
If we pass ProviderContainerConnection
podman extension could add a security checking that the providerId corresponds and we are not sending one registered by another extensions.
however;
ContainerProviderConnection
would be easier as extension get this object pretty easily through, and is something used in the BuildOptions
, VolumeCreateOptions
, pullImage
, createNetwork
etc....
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 added additional optional parameter connection: ProviderContainerConnection
, so clients can get instance using provider.getContainerConnections
and use it to call exec.
You are suggesting to have getConnections() method that would be called when needed, instead of having all of those listeners added to track changes in connections related to podman provider, aren't you? That should work, but should we add that as different pull request, after merging API with exec and implementing publishing? I can definitely add that in this PR, but it would be out of the issue scope IMO. |
I just want to be sure that @axel7083 and others on AI lab extension will be able to use the extension endpoint. If there is an exec endpoint that is useless for other extensions then they won't use it and still keep their own code |
that said, it needs to be something in the middle where we might not have all the endpoints but we need to be sure that what we're adding is working smoothly for the other extensions |
To make some tests in AI Lab I added the following functions import type { ExtensionContext, ProviderContainerConnection, RunOptions, RunResult } from '@podman-desktop/api';
import { extensions, provider } from '@podman-desktop/api';
async function podmanExtensionExperiment(): Promise<void> {
const podman = extensions.getExtension('podman-desktop.podman');
if(!podman) throw new Error('cannot found podman extension api');
const podmanApi: {
exec(args: string[], connection?: extensionApi.ProviderContainerConnection, options?: RunOptions): Promise<RunResult>;
} = podman.exports;
const machines = await podmanApi.exec(['machine', 'list', '--format=json']);
console.log('podman machine list', JSON.parse(machines.stdout));
const connections: ProviderContainerConnection[] = provider.getContainerConnections();
for (const connection of connections) {
await podmanApi.exec(['run','hello-world'], connection);
}
} I have two connections: After running the function above in AI Lab, I cannot see the hello-world on the qemu machine. $: podman container ls -a
d67b196eac60 quay.io/podman/hello:latest /usr/local/bin/po... 3 minutes ago Exited (0) 3 minutes ago elastic_ganguly
1682a7a50ae1 quay.io/podman/hello:latest /usr/local/bin/po... 3 minutes ago Exited (0) 3 minutes ago pensive_saha
$: podman --connection=podman-machine-default container ls -s
# nothing We seems to have both hello-world container running on the podman default ThroobleshootingFor some weird reason the following command
return the container list of the podman native connection. The only way to get the podman from the qemu is to use the following
|
Looking through podmanConnection.ts and it looks like it can be just moved over to podman extension and used as an API prototype. Whatever extension needs to work with podman directly would be able to use it directly from podman extension avoiding dealing with provider API. |
we can probably iterate there, move as suggested all the options to a single option parameter
then we will be able to start publishing the artifact then we can add the other parts. |
connection?: extensionApi.ProviderContainerConnection, | ||
options?: extensionApi.RunOptions, | ||
): Promise<extensionApi.RunResult> { | ||
return execPodman(args, connection?.connection.vmTypeDisplayName, options); |
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's not the display name to use but the vmType
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.
If I have two wsl vmType, I need to use the connection name to be able to determine which one is supposed to be targeted
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.
Both can be used, because if known display name is passed, it would be converted to vmType, otherwise if the passed value cannot be converted, it is used as as vmType (see execPodman).
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 CONTAINERS_MACHINE_PROVIDER
allow us to target a provider (qemu
, wsl
etc.) but not a specific machine in the provider.
But as Florent said, let's iterate after this PR
Signed-off-by: Denis Golovin <[email protected]>
Signed-off-by: Denis Golovin <[email protected]>
Signed-off-by: Denis Golovin <[email protected]>
Signed-off-by: Denis Golovin <[email protected]>
Co-authored-by: axel7083 <[email protected]> Signed-off-by: Denis Golovin <[email protected]>
Signed-off-by: Denis Golovin <[email protected]>
e19c709
to
52090e2
Compare
Signed-off-by: Denis Golovin <[email protected]>
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.
LGTM
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.
ok for step 1
we have a short window until the API goes public with 1.13.0 release
so we can still change the API until that if we see it's not working in the extensions until that time
What does this PR do?
Screenshot / video of UI
What issues does this PR fix or reference?
Related to #5990.
How to test this PR?