From 1aba2c167e0fa76d8650c3e338fa6bc775bb9369 Mon Sep 17 00:00:00 2001 From: Florent Benoit Date: Wed, 10 May 2023 22:26:39 +0200 Subject: [PATCH] fix: use other key than the socket path before podman 4.5, socket path were different for all machines with podman 4.5, socket path is the same for all the machines so some functions were using the path as a key then it leads to lot of errors with invalid data, failure to get the right machine, duplicated things, config from other machines, etc. fixes https://github.com/containers/podman-desktop/issues/2338 Change-Id: I76e23b1cc2656e6fd61d60a265d0b93698f7196d Signed-off-by: Florent Benoit --- extensions/podman/src/extension.ts | 5 ++++- packages/main/src/plugin/configuration-impl.ts | 2 +- packages/main/src/plugin/container-registry.ts | 12 +++++++++--- packages/main/src/plugin/provider-impl.ts | 3 ++- packages/main/src/tray-menu.ts | 8 +++++--- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/extensions/podman/src/extension.ts b/extensions/podman/src/extension.ts index 399f65f99a6..fbdb6a418fc 100644 --- a/extensions/podman/src/extension.ts +++ b/extensions/podman/src/extension.ts @@ -94,6 +94,7 @@ async function updateMachines(provider: extensionApi.Provider): Promise { if (previousStatus !== status) { // notify status change listeners.forEach(listener => listener(machine.Name, status)); + podmanMachinesStatuses.set(machine.Name, status); } podmanMachinesInfo.set(machine.Name, { name: machine.Name, @@ -394,7 +395,9 @@ async function registerProviderFor(provider: extensionApi.Provider, machineInfo: }, }; - monitorPodmanSocket(socketPath, machineInfo.name); + // Since Podman 4.5, machines are using the same path for all sockets of machines + // so a machine is not distinguishable from another one. + // monitorPodmanSocket(socketPath, machineInfo.name); containerProviderConnections.set(machineInfo.name, containerProviderConnection); const disposable = provider.registerContainerProviderConnection(containerProviderConnection); diff --git a/packages/main/src/plugin/configuration-impl.ts b/packages/main/src/plugin/configuration-impl.ts index 9b79b59998b..f5fa6c5c8cd 100644 --- a/packages/main/src/plugin/configuration-impl.ts +++ b/packages/main/src/plugin/configuration-impl.ts @@ -124,7 +124,7 @@ export class ConfigurationImpl implements containerDesktopAPI.Configuration { getConfigurationKey(): string { if (this.isContainerProviderConnection(this.scope)) { - return `container-connection:${this.scope.endpoint.socketPath}`; + return `container-connection:${this.scope.name}.${this.scope.endpoint.socketPath}`; } else if (this.isKubernetesProviderConnection(this.scope)) { return `kubernetes-connection:${this.scope.endpoint.apiURL}`; } else { diff --git a/packages/main/src/plugin/container-registry.ts b/packages/main/src/plugin/container-registry.ts index d2b9693238d..51c3c27f993 100644 --- a/packages/main/src/plugin/container-registry.ts +++ b/packages/main/src/plugin/container-registry.ts @@ -565,7 +565,8 @@ export class ContainerProviderRegistry { // grab all connections const matchingContainerProvider = Array.from(this.internalProviders.values()).find( containerProvider => - containerProvider.connection.endpoint.socketPath === providerContainerConnectionInfo.endpoint.socketPath, + containerProvider.connection.endpoint.socketPath === providerContainerConnectionInfo.endpoint.socketPath && + containerProvider.connection.name === providerContainerConnectionInfo.name, ); if (!matchingContainerProvider || !matchingContainerProvider.api) { throw new Error('No provider with a running engine'); @@ -690,7 +691,9 @@ export class ContainerProviderRegistry { this.telemetryService.track('createPod'); // grab all connections const matchingContainerProvider = Array.from(this.internalProviders.values()).find( - containerProvider => containerProvider.connection.endpoint.socketPath === selectedProvider.endpoint.socketPath, + containerProvider => + containerProvider.connection.endpoint.socketPath === selectedProvider.endpoint.socketPath && + containerProvider.connection.name === selectedProvider.name, ); if (!matchingContainerProvider || !matchingContainerProvider.libpodApi) { throw new Error('No provider with a running engine'); @@ -1000,7 +1003,9 @@ export class ContainerProviderRegistry { this.telemetryService.track('playKube'); // grab all connections const matchingContainerProvider = Array.from(this.internalProviders.values()).find( - containerProvider => containerProvider.connection.endpoint.socketPath === selectedProvider.endpoint.socketPath, + containerProvider => + containerProvider.connection.endpoint.socketPath === selectedProvider.endpoint.socketPath && + containerProvider.name === selectedProvider.name, ); if (!matchingContainerProvider || !matchingContainerProvider.libpodApi) { throw new Error('No provider with a running engine'); @@ -1020,6 +1025,7 @@ export class ContainerProviderRegistry { const matchingContainerProvider = Array.from(this.internalProviders.values()).find( containerProvider => containerProvider.connection.endpoint.socketPath === selectedProvider.endpoint.socketPath && + containerProvider.connection.name === selectedProvider.name && selectedProvider.status === 'started', ); if (!matchingContainerProvider || !matchingContainerProvider.api) { diff --git a/packages/main/src/plugin/provider-impl.ts b/packages/main/src/plugin/provider-impl.ts index 9c1bcc0b60c..5456a88e413 100644 --- a/packages/main/src/plugin/provider-impl.ts +++ b/packages/main/src/plugin/provider-impl.ts @@ -91,7 +91,8 @@ export class ProviderImpl implements Provider, IDisposable { setInterval(async () => { this.containerProviderConnections.forEach(providerConnection => { const status = providerConnection.status(); - const key = providerConnection.endpoint.socketPath; + // key can't be socket path as for some providers it can be the same + const key = `${providerConnection.name}.${providerConnection.endpoint.socketPath}`; if (status !== this.containerProviderConnectionsStatuses.get(key)) { this.providerRegistry.onDidChangeContainerProviderConnectionStatus(this, providerConnection); this.containerProviderConnectionsStatuses.set(key, status); diff --git a/packages/main/src/tray-menu.ts b/packages/main/src/tray-menu.ts index 08f32338986..868efc7fb47 100644 --- a/packages/main/src/tray-menu.ts +++ b/packages/main/src/tray-menu.ts @@ -158,7 +158,7 @@ export class TrayMenu { childItems: [], }; this.menuContainerProviderConnectionItems.set( - providerContainerConnectionInfoMenuItem.endpoint.socketPath, + `${providerContainerConnectionInfoMenuItem.name}.${providerContainerConnectionInfoMenuItem.endpoint.socketPath}`, providerContainerConnectionInfoMenuItem, ); this.updateMenu(); @@ -169,7 +169,7 @@ export class TrayMenu { providerContainerConnectionInfo: ProviderContainerConnectionInfo, ): void { const menuProviderItem = this.menuContainerProviderConnectionItems.get( - providerContainerConnectionInfo.endpoint.socketPath, + `${providerContainerConnectionInfo.name}.${providerContainerConnectionInfo.endpoint.socketPath}`, ); if (menuProviderItem) { menuProviderItem.status = providerContainerConnectionInfo.status; @@ -181,7 +181,9 @@ export class TrayMenu { _provider: ProviderInfo, providerContainerConnectionInfo: ProviderContainerConnectionInfo, ): void { - this.menuContainerProviderConnectionItems.delete(providerContainerConnectionInfo.endpoint.socketPath); + this.menuContainerProviderConnectionItems.delete( + `${providerContainerConnectionInfo.name}.${providerContainerConnectionInfo.endpoint.socketPath}`, + ); this.updateMenu(); }