Skip to content

Commit 5fdabb2

Browse files
committed
Check for podman machine on CLI instead of relying on odo
Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 037cc6b commit 5fdabb2

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

src/odo/odoWrapper.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -416,20 +416,6 @@ export class Odo {
416416
);
417417
}
418418

419-
public async isPodmanPresent(): Promise<boolean> {
420-
try {
421-
const result: CliExitData = await this.execute(
422-
new CommandText('odo', 'version -o json'),
423-
);
424-
if ('podman' in JSON.parse(result.stdout)) {
425-
return true;
426-
}
427-
} catch {
428-
//ignore
429-
}
430-
return false;
431-
}
432-
433419
/**
434420
* Bind a component to a bindable service by modifying the devfile
435421
*

src/openshift/component.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as fs from 'fs/promises';
77
import * as JSYAML from 'js-yaml';
8+
import { platform } from 'os';
89
import * as path from 'path';
910
import { which } from 'shelljs';
1011
import { commands, debug, DebugConfiguration, DebugSession, Disposable, EventEmitter, extensions, ProgressLocation, Uri, window, workspace } from 'vscode';
@@ -15,6 +16,7 @@ import { CommandProvider, StarterProject } from '../odo/componentTypeDescription
1516
import { Odo } from '../odo/odoWrapper';
1617
import { ComponentWorkspaceFolder } from '../odo/workspace';
1718
import sendTelemetry, { NewComponentCommandProps } from '../telemetry';
19+
import { ChildProcessUtil, CliExitData } from '../util/childProcessUtil';
1820
import { Progress } from '../util/progress';
1921
import { vsCommand, VsCommandError } from '../vscommand';
2022
import AddServiceBindingViewLoader, { ServiceBindingFormResponse } from '../webview/add-service-binding/addServiceBindingViewLoader';
@@ -217,11 +219,20 @@ export class Component extends OpenShiftItem {
217219
}
218220

219221
private static async checkForPodman(): Promise<boolean> {
220-
if (await Component.odo.isPodmanPresent()) {
221-
return true;
222-
}
223-
const podmanOnPath = which('podman');
224-
if (podmanOnPath) {
222+
const podmanPath = which('podman');
223+
if (podmanPath) {
224+
if (platform() === 'linux') {
225+
return true;
226+
}
227+
try {
228+
const resultRaw: CliExitData = await ChildProcessUtil.Instance.execute(`"${podmanPath}" machine list --format json`);
229+
const resultObj: { Running: boolean }[] = JSON.parse(resultRaw.stdout);
230+
if (resultObj.length === 1 && resultObj[0].Running) {
231+
return true;
232+
}
233+
} catch (e) {
234+
// do nothing; something is wrong with the podman setup
235+
}
225236
const SETUP_INSTRUCTIONS = 'Open setup instructions';
226237
void window.showErrorMessage('Podman is present on the system, but is not fully set up yet.', SETUP_INSTRUCTIONS)
227238
.then(result => {

test/integration/odoWrapper.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { expect } from 'chai';
88
import * as fs from 'fs/promises';
99
import { suite, suiteSetup } from 'mocha';
1010
import * as path from 'path';
11-
import { which } from 'shelljs';
1211
import * as tmp from 'tmp';
1312
import { promisify } from 'util';
1413
import { Uri, workspace } from 'vscode';
@@ -228,12 +227,6 @@ suite('./odo/odoWrapper.ts', function () {
228227
expect(componentDetails.starterProjects).is.not.empty;
229228
});
230229

231-
test('isPodmanPresent()', async function() {
232-
const isPodmanPresent = await Odo.Instance.isPodmanPresent();
233-
const whichImplementationPodmanPresent = which('podman') !== null;
234-
expect(isPodmanPresent).to.equal(whichImplementationPodmanPresent);
235-
});
236-
237230
test('getStarterProjects()', async function() {
238231
const starterProjects = await Odo.Instance.getStarterProjects({
239232
registryName: 'DefaultDevfileRegistry',

0 commit comments

Comments
 (0)