Skip to content

Commit

Permalink
fix: check if machine init rootful flag supported
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed Sep 10, 2023
1 parent 18ecd16 commit fdb194f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion extensions/podman/package.json
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions extensions/podman/src/extension.ts
Expand Up @@ -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<void> {
Expand All @@ -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));
}

Expand Down Expand Up @@ -1072,6 +1074,13 @@ export async function deactivate(): Promise<void> {
});
}

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
Expand Down
15 changes: 14 additions & 1 deletion extensions/podman/src/podman-install.ts
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit fdb194f

Please sign in to comment.