From fdb194f5d8294d71a6acb3e18cb1a4337915dc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 10 Sep 2023 22:34:18 +0200 Subject: [PATCH] fix: check if machine init rootful flag supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders F Björklund --- extensions/podman/package.json | 3 ++- extensions/podman/src/extension.ts | 9 +++++++++ extensions/podman/src/podman-install.ts | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/extensions/podman/package.json b/extensions/podman/package.json index e7bf75433552e..fcf1d6febdcdd 100644 --- a/extensions/podman/package.json +++ b/extensions/podman/package.json @@ -104,7 +104,8 @@ "type": "boolean", "default": true, "scope": "ContainerProviderConnectionFactory", - "description": "Machine with root privileges" + "description": "Machine with root privileges", + "when": "podman.isRootfulMachineInitSupported == true" }, "podman.factory.machine.user-mode-networking": { "type": "boolean", diff --git a/extensions/podman/src/extension.ts b/extensions/podman/src/extension.ts index 050599cfd2eeb..923caeadf4fae 100644 --- a/extensions/podman/src/extension.ts +++ b/extensions/podman/src/extension.ts @@ -659,6 +659,7 @@ async function registerUpdatesIfAny( } } +export const ROOTFUL_MACHINE_INIT_SUPPORTED_KEY = 'podman.isRootfulMachineInitSupported'; export const USER_MODE_NETWORKING_SUPPORTED_KEY = 'podman.isUserModeNetworkingSupported'; export async function activate(extensionContext: extensionApi.ExtensionContext): Promise { @@ -669,6 +670,7 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): const version: string | undefined = installedPodman?.version; if (version) { + extensionApi.context.setValue(ROOTFUL_MACHINE_INIT_SUPPORTED_KEY, isRootfulMachineInitSupported(version)); extensionApi.context.setValue(USER_MODE_NETWORKING_SUPPORTED_KEY, isUserModeNetworkingSupported(version)); } @@ -1072,6 +1074,13 @@ export async function deactivate(): Promise { }); } +const PODMAN_MINIMUM_VERSION_FOR_ROOTFUL_MACHINE_INIT = '4.1.0'; + +// Checks if rootful machine init is supported. +export function isRootfulMachineInitSupported(podmanVersion: string) { + return compareVersions(podmanVersion, PODMAN_MINIMUM_VERSION_FOR_ROOTFUL_MACHINE_INIT) >= 0; +} + const PODMAN_MINIMUM_VERSION_FOR_USER_MODE_NETWORKING = '4.6.0'; // Checks if user mode networking is supported. Only Windows platform allows this parameter to be tuned diff --git a/extensions/podman/src/podman-install.ts b/extensions/podman/src/podman-install.ts index 9491d128973a1..250df388fec57 100755 --- a/extensions/podman/src/podman-install.ts +++ b/extensions/podman/src/podman-install.ts @@ -29,7 +29,12 @@ import { getAssetsFolder } from './util'; import { getDetectionChecks } from './detection-checks'; import { BaseCheck } from './base-check'; import { MacCPUCheck, MacMemoryCheck, MacPodmanInstallCheck, MacVersionCheck } from './macos-checks'; -import { isUserModeNetworkingSupported, USER_MODE_NETWORKING_SUPPORTED_KEY } from './extension'; +import { + isRootfulMachineInitSupported, + ROOTFUL_MACHINE_INIT_SUPPORTED_KEY, + isUserModeNetworkingSupported, + USER_MODE_NETWORKING_SUPPORTED_KEY, +} from './extension'; const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); @@ -132,6 +137,10 @@ export class PodmanInstall { // write podman version if (newInstalledPodman) { this.podmanInfo.podmanVersion = newInstalledPodman.version; + extensionApi.context.setValue( + ROOTFUL_MACHINE_INIT_SUPPORTED_KEY, + isRootfulMachineInitSupported(newInstalledPodman.version), + ); extensionApi.context.setValue( USER_MODE_NETWORKING_SUPPORTED_KEY, isUserModeNetworkingSupported(newInstalledPodman.version), @@ -181,6 +190,10 @@ export class PodmanInstall { provider.updateDetectionChecks(getDetectionChecks(installedPodman)); provider.updateVersion(updateInfo.bundledVersion); this.podmanInfo.ignoreVersionUpdate = undefined; + extensionApi.context.setValue( + ROOTFUL_MACHINE_INIT_SUPPORTED_KEY, + isRootfulMachineInitSupported(updateInfo.bundledVersion), + ); extensionApi.context.setValue( USER_MODE_NETWORKING_SUPPORTED_KEY, isUserModeNetworkingSupported(updateInfo.bundledVersion),