Skip to content
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

fix: check if machine init rootful flag supported #3854

Merged
merged 1 commit into from Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -664,6 +664,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 @@ -674,6 +675,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));
isMovedPodmanSocket = isPodmanSocketLocationMoved(version);
}
Expand Down Expand Up @@ -1080,6 +1082,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_NEW_SOCKET_LOCATION = '4.5.0';

export function isPodmanSocketLocationMoved(podmanVersion: string) {
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