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

Do not check resources on Linux #1088

Merged
merged 2 commits into from
May 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/backend/src/utils/podman.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import { beforeEach, expect, test, describe, vi } from 'vitest';
import { beforeEach, expect, test, describe, vi, afterEach } from 'vitest';
import * as podmanDesktopApi from '@podman-desktop/api';
import * as utils from '../utils/podman';
import type { ContainerEngineInfo } from '@podman-desktop/api';
Expand All @@ -38,6 +38,7 @@ vi.mock('@podman-desktop/api', () => {
return {
env: {
isWindows: false,
isLinux: false,
},
configuration: {
getConfiguration: () => config,
Expand Down Expand Up @@ -330,6 +331,21 @@ describe('checkContainerConnectionStatusAndResources', () => {
engineName: 'enginerName',
engineType: 'podman',
};
afterEach(() => {
vi.mocked(podmanDesktopApi.env).isLinux = false;
});
test('return native on Linux', async () => {
vi.mocked(podmanDesktopApi.env).isLinux = true;
vi.spyOn(utils, 'getFirstRunningPodmanConnection').mockReturnValue(undefined);
const result = await utils.checkContainerConnectionStatusAndResources({
memoryNeeded: 10,
context: 'inference',
});
expect(result).toStrictEqual({
status: 'native',
canRedirect: true,
});
});
test('return noMachineInfo if there is no running podman connection', async () => {
vi.spyOn(utils, 'getFirstRunningPodmanConnection').mockReturnValue(undefined);
const result = await utils.checkContainerConnectionStatusAndResources({
Expand Down
13 changes: 10 additions & 3 deletions packages/backend/src/utils/podman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,23 @@ export async function isQEMUMachine(): Promise<boolean> {
export async function checkContainerConnectionStatusAndResources(
modelInfo: ModelCheckerInfo,
): Promise<ContainerConnectionInfo> {
// starting from podman desktop 1.10 we have the navigate functions
const hasNavigateFunction = !!navigation.navigateToResources;

if (env.isLinux) {
return {
status: 'native',
canRedirect: hasNavigateFunction,
};
}

let connection: ProviderContainerConnection | undefined = undefined;
try {
connection = getFirstRunningPodmanConnection();
} catch (e) {
console.log(String(e));
}

// starting from podman desktop 1.10 we have the navigate functions
const hasNavigateFunction = !!navigation.navigateToResources;

if (!connection) {
return {
status: 'no-machine',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ let actionName: string | undefined = '';
$: updateTitleDescription(connectionInfo);

function updateTitleDescription(connectionInfo: ContainerConnectionInfo) {
if (connectionInfo.status === 'native') {
return;
}

if (connectionInfo.status === 'no-machine') {
title = 'No Podman Machine is running';
description = 'Please start a Podman Machine before proceeding further.';
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/src/models/IContainerConnectionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
export type ContainerConnectionInfo =
| RunningContainerConnection
| LowResourcesContainerConnection
| NoContainerConnection;
| NoContainerConnection
| NativeContainerConnection;

export type ContainerConnectionInfoStatus = 'running' | 'no-machine' | 'low-resources';

Expand All @@ -44,3 +45,8 @@ export interface NoContainerConnection {
status: 'no-machine';
canRedirect: boolean;
}

export interface NativeContainerConnection {
status: 'native';
canRedirect: boolean;
}