From 008a0f9095675b9fc844cc8f50eef4c835a5a180 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 10 Jan 2024 12:04:05 -0500 Subject: [PATCH] Check for podman machine on CLI instead of relying on odo Signed-off-by: David Thompson --- src/odo/odoWrapper.ts | 14 -------------- src/openshift/component.ts | 21 ++++++++++++++++----- test/integration/odoWrapper.test.ts | 7 ------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/odo/odoWrapper.ts b/src/odo/odoWrapper.ts index b886d6b5a..858509fce 100644 --- a/src/odo/odoWrapper.ts +++ b/src/odo/odoWrapper.ts @@ -293,20 +293,6 @@ export class Odo { ); } - public async isPodmanPresent(): Promise { - try { - const result: CliExitData = await this.execute( - new CommandText('odo', 'version -o json'), - ); - if ('podman' in JSON.parse(result.stdout)) { - return true; - } - } catch { - //ignore - } - return false; - } - /** * Bind a component to a bindable service by modifying the devfile * diff --git a/src/openshift/component.ts b/src/openshift/component.ts index a782f87b9..f98acc1d4 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -5,6 +5,7 @@ import * as fs from 'fs/promises'; import * as JSYAML from 'js-yaml'; +import { platform } from 'os'; import * as path from 'path'; import { which } from 'shelljs'; import { commands, debug, DebugConfiguration, DebugSession, Disposable, EventEmitter, extensions, ProgressLocation, Uri, window, workspace } from 'vscode'; @@ -15,6 +16,7 @@ import { CommandProvider, StarterProject } from '../odo/componentTypeDescription import { Odo } from '../odo/odoWrapper'; import { ComponentWorkspaceFolder } from '../odo/workspace'; import sendTelemetry, { NewComponentCommandProps } from '../telemetry'; +import { ChildProcessUtil, CliExitData } from '../util/childProcessUtil'; import { Progress } from '../util/progress'; import { vsCommand, VsCommandError } from '../vscommand'; import AddServiceBindingViewLoader, { ServiceBindingFormResponse } from '../webview/add-service-binding/addServiceBindingViewLoader'; @@ -217,11 +219,20 @@ export class Component extends OpenShiftItem { } private static async checkForPodman(): Promise { - if (await Odo.Instance.isPodmanPresent()) { - return true; - } - const podmanOnPath = which('podman'); - if (podmanOnPath) { + const podmanPath = which('podman'); + if (podmanPath) { + if (platform() === 'linux') { + return true; + } + try { + const resultRaw: CliExitData = await ChildProcessUtil.Instance.execute(`"${podmanPath}" machine list --format json`); + const resultObj: { Running: boolean }[] = JSON.parse(resultRaw.stdout); + if (resultObj.length === 1 && resultObj[0].Running) { + return true; + } + } catch (e) { + // do nothing; something is wrong with the podman setup + } const SETUP_INSTRUCTIONS = 'Open setup instructions'; void window.showErrorMessage('Podman is present on the system, but is not fully set up yet.', SETUP_INSTRUCTIONS) .then(result => { diff --git a/test/integration/odoWrapper.test.ts b/test/integration/odoWrapper.test.ts index dfe928670..35e5fb3e6 100644 --- a/test/integration/odoWrapper.test.ts +++ b/test/integration/odoWrapper.test.ts @@ -8,7 +8,6 @@ import { expect } from 'chai'; import * as fs from 'fs/promises'; import { suite, suiteSetup } from 'mocha'; import * as path from 'path'; -import { which } from 'shelljs'; import * as tmp from 'tmp'; import { promisify } from 'util'; import { Uri, workspace } from 'vscode'; @@ -165,12 +164,6 @@ suite('./odo/odoWrapper.ts', function () { expect(componentDetails.starterProjects).is.not.empty; }); - test('isPodmanPresent()', async function() { - const isPodmanPresent = await Odo.Instance.isPodmanPresent(); - const whichImplementationPodmanPresent = which('podman') !== null; - expect(isPodmanPresent).to.equal(whichImplementationPodmanPresent); - }); - test('getStarterProjects()', async function() { const starterProjects = await Odo.Instance.getStarterProjects({ registryName: 'DefaultDevfileRegistry',