From 12692fd4bcf2619b6432e222962f622eaa4860e8 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 16 Feb 2024 12:02:26 +0100 Subject: [PATCH] improve machine error when running on Linux On Linux, Podman Desktop can talk to the Podman socket of the host and to the ones of the Linux VM. As outlinted in #42, talking to socket of the host's Podman is currently not supported by the extension. While logging into the container registry is perfectly fine, running subscriptio-manager is not; it requires root privileges to install and run it. So instead of a silent error, throw a user-visible error indicating that it's currently not supported on a Linux host. Fixes: #42 Signed-off-by: Valentin Rothberg --- src/extension.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 610ad61..e5bcd0c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -27,6 +27,7 @@ import path from 'node:path'; import { accessSync, constants, existsSync, readFileSync } from 'node:fs'; import { restartPodmanMachine, runRpmInstallSubscriptionManager, runSubscriptionManager, runSubscriptionManagerActivationStatus, runSubscriptionManagerRegister } from './podman-cli'; import { SubscriptionManagerClient } from '@redhat-developer/rhsm-client'; +import { isLinux } from './util'; let loginService: RedHatAuthenticationService; let currentSession: extensionApi.AuthenticationSession | undefined; @@ -156,7 +157,7 @@ async function createOrReuseActivationKey() { function isPodmanMachineRunning(): boolean { const conns = extensionApi.provider.getContainerConnections(); - const startedPodman = conns.filter(conn => conn.providerId === 'podman' && conn.connection.status() === 'started'); + const startedPodman = conns.filter(conn => conn.providerId === 'podman' && conn.connection.status() === 'started' && !conn.connection.endpoint.socketPath.startsWith("/run/user/")); return startedPodman.length === 1; } @@ -255,7 +256,11 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): location: extensionApi.ProgressLocation.TASK_WIDGET, title: 'Activating Red Hat Subscription' }, async (progress) => { if (!isPodmanMachineRunning()) { - await extensionApi.window.showInformationMessage('Podman machine is not running. Please start it and try again.'); + if (isLinux()) { + await extensionApi.window.showInformationMessage('Signing into a Red Hat account requires a running Podman machine, and is currently not supported on a Linux host. Please start a Podman machine and try again.'); + } else { + await extensionApi.window.showInformationMessage('Signing into a Red Hat account requires a running Podman machine. Please start one and try again.'); + } return; } else { if (!(await isSubscriptionManagerInstalled())) {